<?php

namespace app\astrologer\controller\v5;

use app\aliyun\controller\AliyunFilterWord;
use app\astrologer\controller\AstrAuth;
use app\common\cachemodel\AppConfig;
use app\common\cachemodel\zlcr2\Zlcr2AstrTasks;
use app\common\cachemodel\zlcr2\Zlcr2QuestionUserView;
use app\common\cachemodel\zlcr2\Zlcr2UserAddQuestion;
use app\common\cachemodel\zlcr2\Zlcr2UserQuestion;
use app\common\cachemodel\zlcr2\Zlcr2UserQuestionComment;
use app\common\cachemodel\zlcr3\Zlcr3ConsultAccount;
use app\common\cachemodel\ZlcrAppeal;
use app\common\cachemodel\ZlcrAstr;
use app\common\cachemodel\ZlcrAstrMessage;
use app\common\cachemodel\ZlcrTag;
use app\common\lib\Alidayu;
use app\common\lib\Push;
use app\common\lib\Util;
use app\common\model\MessageCenter;
use app\common\model\Recode;
use app\common\model\User;
use app\zyhsapi\lib\ZyhsPush;
use app\zyhsapi\model\ZyhsAstrTasks;
use app\zyhsapi\model\ZyhsConfig;
use app\zyhsapi\model\ZyhsConsultChatRecordDetails;
use app\zyhsapi\model\ZyhsMessageCenter;
use app\zyhsapi\model\ZyhsRecode;
use app\zyhsapi\model\ZyhsUser;
use app\zyhsapi\model\ZyhsUserAddQuestion;
use app\zyhsapi\model\ZyhsUserQuestion;
use app\zyhsapi\model\ZyhsUserQuestionComment;
use Darabonba\GatewaySpi\Models\InterceptorContext\request;
use think\Cache;
use think\Db;
use think\Log;
use think\response\Json;

class Question extends AstrAuth
{
    /**
     * 获取接单列表   已完成
     */
    public function questionWaitingList()
    {
        $questionModel = new Zlcr2UserQuestion();
        $astrModel = new ZlcrAstr();
        $astrTaskModel = new Zlcr2AstrTasks();
        $zyhsAstrTasksModel = new ZyhsAstrTasks();
        // 完善资料 状态
        $isCompleteInformation = isset($this->astrInfo['extend']['is_complete_information']) ? 1 : 0;
        $nowTime = $this->request->time();
        if (!(in_array($this->headers['app-type'], ['ios', 'android'], true) && !$isCompleteInformation))
        {   // $waitingListIds = $questionModel->getQuestionWaitingListIds(1);
            $astrAnswerGids = $astrTaskModel->getAstrAnswerGids($this->astrInfo);
            // 获取弃答 问题id
            $discardQids = $astrTaskModel->getDiscardQids($this->astrInfo['id']);
            // 从数据库获取待接单任务
            $waitingListIds = $questionModel->where(['status' => ['in', [2, 4]], 'astr_id' => 0, 'gid' => ['in', $astrAnswerGids], 'id' => ['not in', $discardQids]])->order('consult_time asc')->limit(10)->column('id');

            $questionInfos = $questionModel->batchGetInfoByIds($waitingListIds, ['status', 'is_anonymity', 'uid', 'gid', 'activity_discount', 'question_type', 'consult_time', 'question', 'question_des', 'id', 'astr_id']);

            $questionAnswerConfig = (new AppConfig())->configInfo('question_answer');
            $showDelayTime = (int)($questionAnswerConfig['show_delay_time'] ?? 0);
            foreach ($questionInfos as $qidItem => $value)
            {
                if (!$this->isConsultAstro && $nowTime - $value['consult_time'] <= $showDelayTime)
                {   // 不是 准有好事 咨询师
                    unset($questionInfos[$qidItem]);
                    continue;
                }
                $questionInfos[$qidItem]['app_type'] = 1;
            }
            // 当前占星师 是否是准有好事 咨询师
            if ($this->isConsultAstro)
            {   // 是咨询师
                $isPause = isset($this->consultAccountInfo['extend']['question_pause_time']) && $this->consultAccountInfo['extend']['question_pause_time'] > $this->request->time();
                if ($isPause)
                {   // 咨询资格 冻结
                    $hintData = [
                        'content' => '',
                        'desc' => '',
                    ];
                    $pauseTime = $this->consultAccountInfo['extend']['question_pause_time'] - $this->request->time();
                    if ($pauseTime > 2678400)
                    {// 冻结 时间 大于 1个月(31天)
                        $hintData['content'] = '你的准有好事的问答接单资格被冻结，如有疑问请联系官方';
                    } else
                    {
                        $str = '';
                        if ($pauseTime > 86400)
                        {
                            $str = floor($pauseTime / 86400) . '天';
                        }
                        if ($pauseTime > 3600)
                        {
                            $str = ceil($pauseTime / 3600) . '小时';
                        }
                        $hintData['content'] = "你的准有好事的问答接单资格被冻结，将在{$str}后自动解封。";
                    }
                } else
                {
                    $zyhsUserQuestionModel = new ZyhsUserQuestion();
                    // 获取可接单 问题类型
                    $ZyhsQuestionAnswerTypes = (new Zlcr3ConsultAccount())->getAstroQuestionType($this->consultAccountInfo);
                    // // 获取弃答 问题ids
                    // $zyhsDiscardQids = $zyhsAstrTasksModel->getDiscardQids($this->astrInfo['id']);
                    // // 获取进行中 的问题ids
                    // $this->request->get(['page' => -1]);
                    // $zyhsTaskLists = $zyhsAstrTasksModel->getListPage($this->astrInfo['id'], 'create_time', ['id', 'qid'], 1);
                    // $zyhsQids = $zyhsTaskLists['data'] ? array_column($zyhsTaskLists['data'], 'qid') : [];
                    // $zyhsDiscardQids = array_merge($zyhsDiscardQids, $zyhsQids); // 合并弃答和进行中
                    $zyhsReceivedQid = $zyhsAstrTasksModel->getAstroReceivedQid($this->astrInfo['id']);
                    // 从数据库获取待接单任务 可接单时间 在 下单后7小时25分钟以内 并且 弃答次数 小于等于3
                    $t = time() - 7 * 60 * 60 - 25 * 60;
                    $waitingListIds = $zyhsUserQuestionModel->where(['status' => 1, 'question_type' => ['in', $ZyhsQuestionAnswerTypes], 'id' => ['not in', $zyhsReceivedQid], 'create_time' => ['>', $t], 'discard_num' => ['<=', 3]])->order('create_time asc')->limit(10)->column('id');

                    $testAccountConfig = (new ZyhsConfig())->configInfo('rtc');
                    $testAstrIds = explode(',', $testAccountConfig['test_user']);
                    $testUids = explode(',', $testAccountConfig['zyhsapp_test_user_id']);
                    $isTestAstr = in_array($this->astrInfo['id'], $testAstrIds, false);
                    // 获取问题详情
                    $zyhsQuestionInfos = $zyhsUserQuestionModel->batchGetInfoByIds($waitingListIds, ['status', 'uid', 'gid', 'question_type', 'create_time', 'question', 'id', 'good_amount', 'consult_num']);
                    foreach ($zyhsQuestionInfos as $qidItem => $value)
                    {
                        if (!$isTestAstr && in_array($value['uid'], $testUids, false))
                        {
                            unset($zyhsQuestionInfos[$qidItem]);
                            continue;
                        }
                        $zyhsQuestionInfos[$qidItem]['app_type'] = 2;
                        $zyhsQuestionInfos[$qidItem]['consult_time'] = $value['create_time'];
                        $zyhsQuestionInfos[$qidItem]['is_anonymity'] = 0;
                    }

                    $questionInfoList = $questionInfos + $zyhsQuestionInfos;
                    $questionInfoListSort = array_column($questionInfoList, 'consult_time', 'id');
                    // 通过值进行正序排序   小到大
                    asort($questionInfoListSort);
                    $resQuestionInfoList = [];
                    foreach ($questionInfoListSort as $qid => $sort)
                    {
                        $resQuestionInfoList[$qid] = $questionInfoList[$qid];
                    }
                    $questionInfos = $resQuestionInfoList;
                }
            }
        } else
        {
            $questionInfos = [];
        }

        $resData = [];
        $userInfoList = [];
        $zyhsUserInfoList = [];
        $goodPrice = [];    // 没有打折情况下分成
        $goodInfo = Util::getZhunleQuestionAnswerConfig();
        foreach ($questionInfos as $qid => $questionInfoItem)
        {   // 判断是否可以接单     app_type = 1 准了    app_type = 2 准有好事
            if (($questionInfoItem['app_type'] === 1 && ($questionInfoItem['status'] === 2 || ($questionInfoItem['status'] === 4 && $questionInfoItem['astr_id'] === 0))) ||
                ($questionInfoItem['app_type'] === 2 && $questionInfoItem['status'] === 1))
            {
                $userDes = '小行星神秘人';
                if ($questionInfoItem['app_type'] === 1)
                {   // 准了
                    $nickname = '匿名用户';
                    $avatar = '/test/question_answer/anonymity1.png';
                    if ($questionInfoItem['is_anonymity'] !== 1)
                    {
                        if (isset($userInfoList[$questionInfoItem['uid']]))
                        {
                            $userDes = $userInfoList[$questionInfoItem['uid']]['user_des'];
                            $nickname = $userInfoList[$questionInfoItem['uid']]['nickname'];
                            $avatar = $userInfoList[$questionInfoItem['uid']]['avatar'];
                        } else
                        {
                            $userInfo = (new User())->getUserinfo(['id' => $questionInfoItem['uid']]);
                            if ($userInfo['rid'])
                            {
                                $recode = (new Recode())->getRecode(['id' => $userInfo['rid']]);
                                if ($recode)
                                {
                                    $utilModel = new Util();
                                    $userDes = '日' . $utilModel->recodeAstroShorthand($recode['sun']) . '月' . $utilModel->recodeAstroShorthand($recode['moon']) . '升' . $utilModel->recodeAstroShorthand($recode['asc']);
                                }
                            }
                            $nickname = $userInfo['nickname'];
                            $avatar = $userInfo['avatar'];
                            $userInfoList[$questionInfoItem['uid']] = [
                                'nickname' => $nickname,
                                'avatar' => $avatar,
                                'user_des' => $userDes,
                            ];
                        }
                    }

                    if (isset($goodPrice[$questionInfoItem['gid']]))
                    {
                        $price = (float)(sprintf("%.2f", $goodPrice[$questionInfoItem['gid']] * $questionInfoItem['activity_discount']));
                    } else
                    {
                        // 获取咨询师等级
                        $level = $this->astrInfo[$astrModel->astrTypeLevelKeyName[$questionInfoItem['question_type']]['level']] ?? 0;
                        $level = $level > 0 ? $level : 1;
                        // 计算未参与活动分成金额
                        $oldPrice = (float)(sprintf('%.2f', $goodInfo[$questionInfoItem['gid']]['price'] * ($astrModel->getAstrQuestionAnswerProportion($this->request->time(), $questionInfoItem['question_type'], $level))));
                        // 计算参与活动后分成金额
                        $price = (float)(sprintf("%.2f", $oldPrice * $questionInfoItem['activity_discount']));
                        // 记录未参与活动分成金额
                        $goodPrice[$questionInfoItem['gid']] = $oldPrice;
                    }
                } else
                {   // 准有好事
                    if (isset($zyhsUserInfoList[$questionInfoItem['uid']]))
                    {
                        $userDes = $zyhsUserInfoList[$questionInfoItem['uid']]['user_des'];
                        $nickname = $zyhsUserInfoList[$questionInfoItem['uid']]['nickname'];
                        $avatar = $zyhsUserInfoList[$questionInfoItem['uid']]['avatar'];
                    } else
                    {
                        $userInfo = (new ZyhsUser())->getInfoById($questionInfoItem['uid']);
                        if ($userInfo['rid'])
                        {
                            $recode = (new ZyhsRecode())->getInfoById($userInfo['rid']);
                            if ($recode)
                            {
                                $utilModel = new Util();
                                $userDes = '日' . $utilModel->recodeAstroShorthand($recode['sun']) . '月' . $utilModel->recodeAstroShorthand($recode['moon']) . '升' . $utilModel->recodeAstroShorthand($recode['asc']);
                            }
                        }
                        $nickname = $userInfo['nickname'];
                        $avatar = $userInfo['avatar'];
                        $zyhsUserInfoList[$questionInfoItem['uid']] = [
                            'nickname' => $nickname,
                            'avatar' => $avatar,
                            'user_des' => $userDes,
                        ];
                    }

                    $price = (float)(sprintf("%.2f", (($questionInfoItem['good_amount'] / $questionInfoItem['consult_num']) * 0.25) / 10));

                    $questionInfoItem['question_des'] = $questionInfoItem['question'];
                    $questionInfoItem['question'] = '';
                }

                $price = Util::getAfterTaxAmount($price); // 扣除手续费及营业税费
                $resData[] = [
                    'app_type' => $questionInfoItem['app_type'],
                    'nickname' => $nickname,
                    'avatar' => $avatar,
                    'create_time' => Util::timeToStr($questionInfoItem['consult_time']),
                    'user_des' => $userDes,
                    'qid' => $questionInfoItem['id'],
                    'type' => $questionInfoItem['question_type'],
                    'question' => $questionInfoItem['question'],
                    'question_des' => $questionInfoItem['question_des'],
                    'price' => $price,
                ];
            }
        }

        $msg = '请求成功';
        if (count($resData) === 0)
        {
            if (in_array($this->headers['app-type'], ['ios', 'android'], true) && !$isCompleteInformation)
            {
                $msg = '请完善信息后，再来接单！';
            } else
            {
                $msg = '接单数据为空，您可以点击刷新按钮进行刷新！';
            }
        }

        $underwayDes = $astrTaskModel->getUnderwayDes($this->astrInfo['id']);
        if ($this->isConsultAstro && empty($underwayDes))
        {
            $underwayDes = $zyhsAstrTasksModel->getUnderwayDes($this->astrInfo['id']);
        }

        return show(config('code.success'), $msg, [
            'underway_des' => $underwayDes,
            'list' => $resData,
            'hint_data' => $hintData ?? null,
        ]);
    }

    /**
     * 问答 咨询师接单 已完成
     */
    public function astrReceiving()
    {
        $qid = input('qid/s', '');
        $appType = input('app_type/d', 0);

        if (empty($qid) || !in_array($appType, [1, 2], true))
        {
            return show(config('code.error'), '请求异常，请稍后再试');
        }
        if ($appType === 1)
        {   // 准了 问答接单
            $questionModel = new Zlcr2UserQuestion();
            $astrModel = new ZlcrAstr();
            if ((int)$this->astrInfo['check_status'] !== 40)
            {
                return show(config('code.error'), '账号状态异常，接单失败');
            }

            $questionInfo = $questionModel->getInfoById($qid, []);
            if (!$questionInfo)
            {
                return show(config('code.error'), '抢单失败，该条任务列表消失');
            }

            if (Cache::get('question_answer:is_underway:' . $this->astrInfo['id'], false))
            {
                return show(config('code.error'), '抢单失败，还有待解答的任务');
            }
            // 判断占星师是否接单功能冻结
            if ($this->astrInfo['answer_pause_time'] > $this->request->time())
            {
                return show(config('code.error'), '因你3天内超10次弃答，问答接单资格冻结3天，' . date('m月d日H:i', $this->astrInfo['answer_pause_time']) . '自动解封。');
            }
            // 判断占星师 是否具备接单资格
            $level = $this->astrInfo[$astrModel->astrTypeLevelKeyName[$questionInfo['question_type']]['level']] ?? 0;

            if ($level === 0)
            {
                return show(config('code.error'), '暂不支持解答相关问题，快去考试认证吧～');
            }

            if ($level < 0)
            {
                return show(config('code.error'), '因你的不当行为，问答-占星接单资格已冻结，如有疑问请联系微信：zhunleapp2');
            }

            if ($this->astrInfo[$astrModel->astrTypeLevelKeyName[$questionInfo['question_type']]['score']] < 80)
            {
                return show(config('code.error'), '抢单失败，账号该类型问答接单功能冻结');
            }

            $goodInfo = config('zlcr2_question.info');
            if ($level < $goodInfo[$questionInfo['gid']]['level'])
            {
                return show(config('code.error'), '抢单失败，没有接单资质');
            }

            if (($questionInfo['status'] !== 2) && !($questionInfo['status'] === 4 && $questionInfo['astr_id'] === 0))
            {
                return show(config('code.error'), '抢单失败，请刷新后重试');
            }

            $receivingRes = $questionModel->astrReceivingLock($qid);
            if ($receivingRes)
            {   // 抢单成功
                $questionModel->UpdateData($qid, [
                    'status' => 4,// 待解答
                    'astr_id' => $this->astrInfo['id'],
                    'astr_receiving_time' => $this->request->time(),
                ]);
                // 添加占星师任务表
                $id = (new Zlcr2AstrTasks())->SaveData($this->astrInfo['id'], [
                    'astr_id' => $this->astrInfo['id'],
                    'qa_level' => $level,
                    'qid' => $qid,
                    'question_type' => $questionInfo['question_type'],
                    'status' => 1,
                    'create_time' => $this->request->time(),
                ]);

                // 1、发送占星师回复超时检测队列 1小时内必须回答
                Util::queuePush('question_answer_question_astr_reply_check', ['task_id' => $id], 1800);
                // 2、发送占星师 40分钟内未回复 对占星师进行通知队列
                Util::queuePush('question_answer_astr_reply_notify', ['task_id' => $id], 600);

                return show(config('code.success'), '抢单成功', ['task_id' => (int)$id]);
            } else
            {   // 抢单失败
                return show(config('code.error'), '抢单失败，请刷新后重试');
            }
        } else
        {
            if (!$this->isConsultAstro)
            {
                return show(config('code.error'), '抢单失败，请刷新后重试');
            }

            $zyhsUserQuestionModel = new ZyhsUserQuestion();
            $zyhsAstrTasksModel = new ZyhsAstrTasks();

            $questionInfo = $zyhsUserQuestionModel->getInfoById($qid, []);
            if (!$questionInfo)
            {
                return show(config('code.error'), '抢单失败，该条任务列表消失');
            }

            if (Cache::get('question_answer:is_underway:' . $this->astrInfo['id'], false))
            {
                return show(config('code.error'), '抢单失败，还有待解答的任务');
            }

            $testAccountConfig = (new ZyhsConfig())->configInfo('rtc');
            $testAstrIds = explode(',', $testAccountConfig['test_user']);
            $testUids = explode(',', $testAccountConfig['zyhsapp_test_user_id']);
            $isTestAstr = in_array($this->astrInfo['id'], $testAstrIds, false);
            if (!$isTestAstr && in_array($questionInfo['uid'], $testUids, false))
            {   // 不是测试咨询师账号 且 不能接单测试账号发的问题
                return show(config('code.error'), '抢单失败，请刷新后重试');
            }

            $ZyhsQuestionAnswerTypes = (new Zlcr3ConsultAccount())->getAstroQuestionType($this->consultAccountInfo);
            if (!in_array($questionInfo['question_type'], $ZyhsQuestionAnswerTypes, true))
            {   // zyhs 问答类型不支持占星接单
                return show(config('code.error'), '抢单失败，请刷新后重试');
            }
            // 加锁
            $receivingRes = $zyhsUserQuestionModel->astrReceivingLock($qid, 3, 600);
            if ($receivingRes)
            {   // 抢单成功
                // 判断 是否还有未解答的任务
                if ($questionInfo['receiving_num'] >= $questionInfo['consult_num'])
                {
                    return show(config('code.error'), '抢单失败，请刷新后重试');
                }
                $receivingData = $questionInfo['extend']['receiving_tasks'] ?? [];
                // 获取已经接单 占星师ID
                $receivingAstrIds = array_column($receivingData, 'astr_id');
                if (in_array($this->astrInfo['id'], $receivingAstrIds, true))
                {
                    $zyhsUserQuestionModel->astrReceivingUnLock($qid);
                    return show(config('code.error'), '抢单失败，请刷新后重试');
                }

                // 添加占星师任务表
                $id = $zyhsAstrTasksModel->SaveData($this->astrInfo['id'], [
                    'astr_id' => $this->astrInfo['id'],
                    'uid' => $questionInfo['uid'],
                    'level' => 1,
                    'qid' => $qid,
                    'order_num' => $questionInfo['order_num'],
                    'question_type' => $questionInfo['question_type'],
                    'status' => 1,
                    'create_time' => $this->request->time(),
                    'update_time' => $this->request->time(),
                ]);
                // 记录当前 占星师接单信息
                $receivingData[] = [
                    'task_id' => $id,
                    'astr_id' => $this->astrInfo['id'],
                ];
                $questionInfo['extend']['receiving_tasks'] = $receivingData;
                $updateData = [
                    'uid' => $questionInfo['uid'],
                    'extend' => $questionInfo['extend'],
                    'receiving_num' => count($questionInfo['extend']['receiving_tasks']),   // 已接单人数
                    'update_time' => $this->request->time(),
                ];
                if ($updateData['receiving_num'] >= $questionInfo['consult_num'])
                {   // 全部接单
                    $updateData['status'] = 2;
                }
                // 更新问答信息
                $zyhsUserQuestionModel->UpdateData($qid, $updateData);
                // 删除锁
                $zyhsUserQuestionModel->astrReceivingUnLock($qid);
                // 1、发送占星师回复超时检测队列 30分钟内必须回答
                Util::queuePush('zyhs_question_answer_question_astr_reply_check', ['task_id' => $id], 1800);
                // 2、发送占星师 15分钟内未回复 对占星师进行通知队列
                Util::queuePush('zyhs_question_answer_astr_reply_notify', ['task_id' => $id], 900);

                return show(config('code.success'), '抢单成功', ['task_id' => $id]);
            } else
            {
                return show(config('code.error'), '抢单失败，请刷新后重试');
            }
        }
    }

    /**
     * 咨询师 进行中列表    已完成
     */
    public function astrTaskList()
    {
        $type = input('type/d', 1); // 1=> 进行中 2=> 已完成
        $astrModel = new ZlcrAstr();
        $questionModel = new Zlcr2UserQuestion();
        $astrTaskModel = new Zlcr2AstrTasks();
        $zyhsAstrTasksModel = new ZyhsAstrTasks();
        $addQuestionModel = new Zlcr2UserAddQuestion();
        $zyhsUserQuestionModel = new ZyhsUserQuestion();
        $zyhsUserAddQuestionModel = new ZyhsUserAddQuestion();
        if ($type === 1)
        {   // 1=>进行中
            $this->request->get(['page' => -1]);
            $taskLists = $astrTaskModel->getListPage($this->astrInfo['id'], 'create_time', ['id', 'qid', 'earning', 'qa_level', 'create_time'], 1);
        } else
        {   // 2=>已完成
            $this->request->get(['page' => 1]);
            $this->request->get(['limit' => 20]);
            $taskLists = $astrTaskModel->getListPage($this->astrInfo['id'], 'update_time', ['id', 'qid', 'earning', 'qa_level', 'create_time'], 2);
        }
        $qids = $taskLists['data'] ? array_column($taskLists['data'], 'qid') : [];
        $taskIdInfo = $taskLists['data'] ? array_column($taskLists['data'], null, 'qid') : [];
        $questionList = $questionModel->batchGetInfoByIds($qids);
        foreach ($taskIdInfo as $k => $v)
        {
            $taskIdInfo[$k]['app_type'] = 1;
        }
        foreach ($questionList as $k => $v)
        {
            $questionList[$k]['app_type'] = 1;
        }
        $zyhsTaskInfo = [];
        if ($this->isConsultAstro)
        {   // 当前用户是 准有好事咨询
            if ($type === 1)
            {   // 1=>进行中
                $this->request->get(['page' => -1]);
                $zyhsTaskLists = $zyhsAstrTasksModel->getListPage($this->astrInfo['id'], 'create_time', ['id', 'qid', 'earning', 'status', 'create_time', 'good_amount', 'consult_num'], 1);
            } else
            {   // 2=>已完成
                $this->request->get(['page' => 1]);
                $this->request->get(['limit' => 20]);
                // type = 3 已完成
                $zyhsTaskLists = $zyhsAstrTasksModel->getListPage($this->astrInfo['id'], 'update_time', ['id', 'qid', 'earning', 'status', 'create_time'], 3);
            }
            $zyhsQids = $zyhsTaskLists['data'] ? array_column($zyhsTaskLists['data'], 'qid') : [];
            $zyhsTaskInfo = $zyhsTaskLists['data'] ? array_column($zyhsTaskLists['data'], null, 'qid') : [];
            $zyhsTaskInfo = $zyhsAstrTasksModel->dataInit($zyhsTaskInfo);
            $zyhsQuestionList = $zyhsUserQuestionModel->batchGetInfoByIds($zyhsQids);
            foreach ($zyhsTaskInfo as $k => $v)
            {
                $zyhsTaskInfo[$k]['app_type'] = 2;
            }
            foreach ($zyhsQuestionList as $k => $v)
            {
                $zyhsQuestionList[$k]['app_type'] = 2;
                $zyhsQuestionList[$k]['create_time'] = $zyhsTaskInfo[$k]['create_time'];
            }

            $questionList = $questionList + $zyhsQuestionList;
            // 重新排序
            $questionInfoListSort = array_column($questionList, 'create_time', 'id');
            // 数组通过 value 排序 (从大到小)
            arsort($questionInfoListSort);
            $resQuestionInfoList = [];
            foreach ($questionInfoListSort as $qid => $sort)
            {
                $resQuestionInfoList[$qid] = $questionList[$qid];
            }
            $questionList = $resQuestionInfoList;
        }

        $resData = [];
        $userInfoList = [];
        $zyhsUserInfoList = [];
        foreach ($questionList as $qid => $questionItem)
        {
            $userDes = '小行星神秘人';
            if ($questionItem['app_type'] === 1)
            {
                $nickname = '匿名用户';
                $avatar = '/test/question_answer/anonymity1.png';
                if ($questionItem['is_anonymity'] !== 1)
                {
                    if (isset($userInfoList[$questionItem['uid']]))
                    {
                        $userDes = $userInfoList[$questionItem['uid']]['user_des'];
                        $nickname = $userInfoList[$questionItem['uid']]['nickname'];
                        $avatar = $userInfoList[$questionItem['uid']]['avatar'];
                    } else
                    {
                        $userInfo = (new User())->getUserinfo(['id' => $questionItem['uid']]);
                        if ($userInfo['rid'])
                        {
                            $recode = (new Recode())->getRecode(['id' => $userInfo['rid']]);
                            if ($recode)
                            {
                                $utilModel = new Util();
                                $userDes = '日' . $utilModel->recodeAstroShorthand($recode['sun']) . '月' . $utilModel->recodeAstroShorthand($recode['moon']) . '升' . $utilModel->recodeAstroShorthand($recode['asc']);
                            }
                        }
                        $nickname = $userInfo['nickname'];
                        $avatar = $userInfo['avatar'];
                        $userInfoList[$questionItem['uid']] = [
                            'nickname' => $nickname,
                            'avatar' => $avatar,
                            'user_des' => $userDes,
                        ];
                    }
                }

                switch ($questionItem['status'])
                {
                    case 4:
                        $endTime = $questionItem['astr_receiving_time'] + 1800 - $this->request->time();
                        $endTime = $endTime > 0 ? $endTime : 0;
                        $tip1 = $endTime;
                        $tip2 = '内完成作答';
                        break;
                    case 5:
                        $tip1 = '';
                        $tip2 = '等待用户追问';
                        if ($questionItem['supplement_answer_num'] === 0 && $questionItem['return_answer_num'] === 0 && $questionItem['reply_time'] + 3600 > $this->request->time())
                        {
                            if ($questionItem['complain_status'] != 1 && $addQuestionModel->getQuestionAddQuestionNum($qid, 0) === 0)
                            {
                                if (isset($questionItem['question_extend']['version']) && Util::CheckAppVersion('2.9.4', $questionItem['question_extend']['version']) !== '小')
                                {   // 用户提问版本 是2.9.4及以上版本
                                    $questionItem['status'] = 25; // 用户可以进行补充回答
                                    $tip2 = '允许对回答补充1次';
                                }
                            }
                        }
                        break;
                    case 6:
                    case 7:
                    case 21:
                        if (empty($questionItem['lock_reason']))
                        {
                            $tip1 = '本单收益：';
                            $tip2 = ((float)$taskIdInfo[$qid]['earning']) . '元';
                        } else
                        {
                            $tip1 = '';
                            $tip2 = '扣除收益';
                        }
                        $questionItem['status'] = 7;
                        break;
                    case 8:
                        $addQuestionList = $addQuestionModel->getQuestionAddQuestionInfo($qid);
                        $addQuestionInfo = array_pop($addQuestionList);
                        if (!$addQuestionInfo)
                        {
                            break;
                        }
                        $endTime = Util::getToAnswerTime($addQuestionInfo['pay_time']);
                        if ($endTime < 0)
                        {   // 超时
                            $tip1 = '';
                            $tip2 = '已超时';
                        } else
                        {   // 未超时
                            $tip1 = $endTime;
                            $tip2 = '内回复追问';
                        }
                        break;
                    case 20: // 退回重答
                        $appealInfo = (new ZlcrAppeal())->where(['type' => 3, 'qid' => $qid, 'status' => ['in', [4, 5]]])->order('id desc')->find();
                        $returnAnswerEndTime = $appealInfo['update_time'] + 21600 - time();
                        if ($returnAnswerEndTime < 0)
                        {
                            // 发送重答超时结算队列
                            Util::queuePush('question_answer_supplement_answer_check', ['appeal_id' => (int)$appealInfo['id'], 'task_id' => (int)$taskIdInfo[$qid]['id']], 5);
                        }
                        $tip1 = $returnAnswerEndTime > 0 ? $returnAnswerEndTime : 0;
                        $tip2 = '倒计时';
                        break;
                    default:
                        $tip1 = '';
                        $tip2 = '';
                }

                $proportion = ($astrModel->getAstrQuestionAnswerProportion($taskIdInfo[$qid]['create_time'], $questionItem['question_type'], $taskIdInfo[$qid]['qa_level']) * 100) . '%';
                $successTime = $questionItem['success_time'] ? date('Y-m-d H:i:s', $questionItem['success_time']) : '';
                $addQuestionNum = $addQuestionModel->getQuestionAddQuestionNum($qid, 0);

                $resData[] = [
                    'qid' => (string)$questionItem['id'],
                    'proportion' => $proportion,
                    'success_time' => $successTime,
                    'add_question_num' => $addQuestionNum,
                    'nickname' => $nickname,
                    'avatar' => $avatar,
                    'create_time' => Util::timeToStr($questionItem['consult_time']),
                    'user_des' => $userDes,
                    'task_id' => (int)$taskIdInfo[$qid]['id'],
                    'type' => $questionItem['question_type'],
                    'question' => $questionItem['question'],
                    'question_des' => $questionItem['question_des'],
                    'des1' => $tip1 ?? '',
                    'des2' => $tip2 ?? '',
                    'status' => $questionItem['status'],
                    'earning' => $type === 1 ? $questionModel->getQuestionEarning2($questionItem, $taskIdInfo[$qid]) : (float)$taskIdInfo[$qid]['earning'],// 回答收益 包含追问的预计收益
                    'astr_receiving_time' => date('Y-m-d H:i:s', $questionItem['astr_receiving_time']), // 接单时间
                ];
            } else
            {
                if (isset($zyhsUserInfoList[$questionItem['uid']]))
                {
                    $userDes = $zyhsUserInfoList[$questionItem['uid']]['user_des'];
                    $nickname = $zyhsUserInfoList[$questionItem['uid']]['nickname'];
                    $avatar = $zyhsUserInfoList[$questionItem['uid']]['avatar'];
                } else
                {
                    $userInfo = (new ZyhsUser())->getInfoById($questionItem['uid']);
                    if ($userInfo['rid'])
                    {
                        $recode = (new ZyhsRecode())->getInfoById($userInfo['rid']);
                        if ($recode)
                        {
                            $utilModel = new Util();
                            $userDes = '日' . $utilModel->recodeAstroShorthand($recode['sun']) . '月' . $utilModel->recodeAstroShorthand($recode['moon']) . '升' . $utilModel->recodeAstroShorthand($recode['asc']);
                        }
                    }
                    $nickname = $userInfo['nickname'];
                    $avatar = $userInfo['avatar'];
                    $zyhsUserInfoList[$questionItem['uid']] = [
                        'nickname' => $nickname,
                        'avatar' => $avatar,
                        'user_des' => $userDes,
                    ];
                }
                // 状态
                //  1=>待解答【已接单】
                //  2=>已弃答
                //  3=>已解答【可追问48小时后自动完成】
                //  4=>已解答【追问回复超时，不可追问48小时后自动完成】
                //  5=>追问待解答
                //  6=>已完成
                //  7=>答案回复超时
                //  8=>已完成且收益扣除【用户申述已取消】
                //  9=>已完成且收益扣除【追问回复超时未完成】
                $tip1 = '';
                $tip2 = '';
                $status = 0;
                switch ($zyhsTaskInfo[$qid]['status'])
                {
                    case 1: // 接单 半小时 内完成作答
                        $endTime = $zyhsTaskInfo[$qid]['create_time'] + 1800 - $this->request->time();
                        $endTime = $endTime > 0 ? $endTime : 0;
                        $tip1 = $endTime;
                        $tip2 = '内完成作答';
                        $status = 4;
                        break;
                    case 3:
                        $tip1 = '';
                        $tip2 = '等待用户追问';
                        $status = 5;
                        break;
                    case 6:
                    case 8:
                    case 9:
                        if (empty($questionItem['lock_reason']))
                        {
                            $tip1 = '本单收益：';
                            $tip2 = ((float)$zyhsTaskInfo[$qid]['earning']) . '元';
                            $status = 6;
                        } else
                        {
                            $tip1 = '';
                            $tip2 = '扣除收益';
                            $status = 7;
                        }
                        break;
                    case 5:
                        $addQuestionList = $zyhsUserAddQuestionModel->getQuestionAddQuestionInfo($zyhsTaskInfo[$qid]['id']);
                        $addQuestionInfo = array_pop($addQuestionList);
                        if (!$addQuestionInfo)
                        {
                            break;
                        }
                        $endTime = Util::getToAnswerTime($addQuestionInfo['pay_time']);
                        if ($endTime < 0)
                        {   // 超时
                            $tip1 = '';
                            $tip2 = '已超时';
                        } else
                        {   // 未超时
                            $tip1 = $endTime;
                            $tip2 = '内回复追问';
                        }
                        $status = 8;
                        break;
                    case 4:
                        $tip1 = '';
                        $tip2 = '已超时';
                        $status = 8;
                        break;
                    default:
                }

                $addQuestionNum = $zyhsUserAddQuestionModel->getQuestionAddQuestionNum($qid, 0);
                if ($type === 1)
                {
                    $earning = $zyhsUserQuestionModel->getQuestionEarning2(['astr_id' => $this->astrInfo['id'], 'task_id' => $zyhsTaskInfo[$qid]['id'], 'good_amount' => $questionItem['good_amount'], 'consult_num' => $questionItem['consult_num'], 'gid' => $questionItem['gid']]);
                } else
                {
                    $earning = (float)$zyhsTaskInfo[$qid]['earning'];
                }

                $resData[] = [
                    'app_type' => $questionItem['app_type'],
                    'qid' => (string)$questionItem['id'],
                    'proportion' => '25%',
                    'success_time' => $zyhsTaskInfo[$qid]['create_time'],
                    'add_question_num' => $addQuestionNum,
                    'nickname' => $nickname,
                    'avatar' => $avatar,
                    'create_time' => Util::timeToStr($questionItem['create_time']),
                    'user_des' => $userDes,
                    'task_id' => (int)$zyhsTaskInfo[$qid]['id'],
                    'type' => $questionItem['question_type'],
                    'question' => '',
                    'question_des' => $questionItem['question'],
                    'des1' => $tip1,
                    'des2' => $tip2,
                    'status' => $status,
                    'earning' => $earning,// 回答收益 包含追问的预计收益
                    'astr_receiving_time' => date('Y-m-d H:i:s', $zyhsTaskInfo[$qid]['create_time']), // 接单时间
                ];
            }
        }

        $msg = '请求成功';
        if (count($resData) === 0)
        {// 1=>进行中 2=>已完成
            if (1 === $type)
            {
                $msg = '进行中的数据为空！';
            } else
            {
                $msg = '已完成的数据为空！';
            }
        }

        $underwayDes = $astrTaskModel->getUnderwayDes($this->astrInfo['id']);
        if ($this->isConsultAstro && empty($underwayDes))
        {
            $underwayDes = $zyhsAstrTasksModel->getUnderwayDes($this->astrInfo['id']);
        }

        return show(config('code.success'), $msg, [
            'underway_des' => $underwayDes,
            'list' => $resData,
        ]);
    }

    /**
     * 弃答-问题    已完成
     */
    public function discardQuestion()
    {
        $taskId = input('task_id/d', '');
        $appType = input('app_type/d', 0);

        if ($appType === 1)
        {
            $questionModel = new Zlcr2UserQuestion();
            $astrTaskModel = new Zlcr2AstrTasks();
            $taskInfo = $astrTaskModel->getInfoById($taskId);
            $questionInfo = $questionModel->getInfoById($taskInfo['qid']);
            if (!$questionInfo || $questionInfo['astr_id'] !== $this->astrInfo['id'])
            {
                return show(config('code.error'), '服务异常，问题不存在');
            }
            if ($questionInfo['status'] !== 4)
            {
                return show(config('code.error'), '服务异常，问题不存在');
            }
            if ($questionInfo['astr_receiving_time'] + 300 < $this->request->time())
            {
                return show(config('code.error'), '接单已超过5分钟，不可弃答。');
            }
            // 获取已弃答次数
            $discardNum = $astrTaskModel->getAstrDiscardQuestionNumByToday($this->astrInfo['id']);
            if ($questionInfo['discard_num'] >= 3)
            {   // 取消订单退款
                $OrderModel = new \app\common\cachemodel\Orders();
                $orders = $OrderModel->getInfoById($questionInfo['order_num']);
                $res = $OrderModel->refund($questionInfo['uid'], $orders, $orders['total_amount']);
                if ($res['status'])
                {
                    // 问题弃答
                    $questionModel->UpdateData($taskInfo['qid'], [
                        'status' => 9,  // 弃答三次退款
                        'astr_id' => 0,
                        'astr_receiving_time' => 0,
                        'discard_num' => $questionInfo['discard_num'] + 1,
                    ]);
                    // 向用户发送消息
                    $msgContent = "你开启的悬赏问答，订单编号：{$questionInfo['order_num']}因问题无法回答自动取消，资金将原路返还，请注意查收。请检查问题重新下单。";
                    // 消息中心添加信息
                    $messageData = [
                        'status' => 0,
                        'is_read' => 0,
                        'range' => $questionInfo['uid'],
                        'type' => 2,
                        'reid' => 0,
                        'cid' => 4,//
                        'title' => '订单取消通知',
                        'content' => $msgContent,// 消息中心跳转地址
                        'link' => "order_details?order_id={$questionInfo['order_num']}&order_type=22&need_auth=0",  // 订单详情
                        'target' => 'local',
                        'create_time' => $this->request->time(),
                    ];
                    (new MessageCenter())->pushMessage($questionInfo['uid'], $messageData);
                    $pushData = ['action' => 'extend', 'target' => 'local', 'link' => "order_details?order_id={$questionInfo['order_num']}&order_type=22&need_auth=0"];
                    // PUSH推送报告首页
                    (new Push())->pushUserMsg($questionInfo['uid'], $msgContent, $pushData);
                    // 发送短信
                    $userInfo = (new User())->getUserinfo(['id' => $questionInfo['uid']]);
                    if ($userInfo && $userInfo['tel'])
                    {
                        Util::sendHySms([$userInfo['tel']], '', 52340, ['order_num' => $questionInfo['order_num']]);
                    }
                } else
                {
                    // 问题弃答 退款失败  弃答
                    $questionModel->UpdateData($taskInfo['qid'], [
                        'astr_id' => 0,
                        'astr_receiving_time' => 0,
                        'discard_num' => $questionInfo['discard_num'] + 1,
                    ]);
                }
            } else
            {   // 问题弃答
                $questionModel->UpdateData($taskInfo['qid'], [
                    'astr_id' => 0,
                    'astr_receiving_time' => 0,
                    'discard_num' => $questionInfo['discard_num'] + 1,
                ]);
            }
            $taskUpdate = [
                'status' => 3,
                'update_time' => $this->request->time(),
            ];
            if ($discardNum >= 10)
            {
                $taskUpdate['is_lock_receiving'] = 1; // 当前任务是否导致账号接单资格冻结 1=>冻结 0=>不冻结
            }
            // 更新占星师任务状态信息
            $astrTaskModel->UpdateData($taskId, $this->astrInfo['id'], $taskUpdate);
            if ($discardNum >= 10)
            {   // 冻结 问答接单资格    3天
                (new ZlcrAstr())->UpdateData($this->astrInfo['id'], ['id' => $this->astrInfo['id']], ['answer_pause_time' => $this->request->time() + 259200]);
                // 给占星师发冻结消息
                // 占星师站内信
                (new ZlcrAstrMessage())->add($questionInfo['astr_id'], [
                    'status' => 0,
                    'is_read' => 0,
                    'astr_id' => $questionInfo['astr_id'],
                    'type' => 9, // 默认消息
                    'title' => '问答接单封禁通知',
                    'content' => '账号封禁通知，因你3天内超10次弃答问答问题，问答接单资格冻结3天处理，3天后自动解封，如有疑问请微信联系。',
                    'target' => 'local',
                    'link' => 'empty',
                    'create_time' => $this->request->time(),
                ]);
            }

            return show(config('code.success'), '弃答成功');
        } else
        {
            $zyhsAstrTasksModel = new ZyhsAstrTasks();
            $zyhsUserQuestionModel = new ZyhsUserQuestion();
            $zyhsTaskInfo = $zyhsAstrTasksModel->getInfoById($taskId);
            if (!$zyhsTaskInfo || $zyhsTaskInfo['astr_id'] !== $this->astrInfo['id'])
            {
                return show(config('code.error'), '服务异常，问题不存在');
            }
            if ($zyhsTaskInfo['status'] !== 1)
            {
                return show(config('code.error'), '操作失败，任务状态异常');
            }
            if ($zyhsTaskInfo['create_time'] + 300 < $this->request->time())
            {
                return show(config('code.error'), '接单已超过5分钟，不可弃答。');
            }
            // 加锁
            $receivingRes = $zyhsUserQuestionModel->astrReceivingLock($zyhsTaskInfo['qid'], 4, 500);
            if ($receivingRes)
            {   // 问题 接单 信息删除
                $questionInfo = $zyhsUserQuestionModel->getInfoById($zyhsTaskInfo['qid']);
                // 更新已接单 任务列表
                $receivingTasks = $questionInfo['extend']['receiving_tasks'];
                $resReceivingTasks = [];
                foreach ($receivingTasks as $receivingTaskItem)
                {
                    if ($taskId !== (int)$receivingTaskItem['task_id'])
                    {
                        $resReceivingTasks[] = $receivingTaskItem;
                    }
                }
                $questionInfo['extend']['receiving_tasks'] = $resReceivingTasks;
                $questionInfoUpdate = [
                    'extend' => $questionInfo['extend'],
                    'receiving_num' => count($resReceivingTasks),   // 已接单人数
                    'uid' => $questionInfo['uid'],
                    'update_time' => $this->request->time(),
                    'status' => 1,
                ];
                // 更新 准有好事 问答问题详情 信息更新
                $zyhsUserQuestionModel->UpdateData($zyhsTaskInfo['qid'], $questionInfoUpdate);
                // 问题 占星师任务 弃答
                $taskUpdate = [
                    'status' => 2,
                    'update_time' => $this->request->time(),
                ];
                // 获取 占星师3日内已弃答次数
                $discardNum = $zyhsAstrTasksModel->getAstrDiscardQuestionNumByToday($this->astrInfo['id']);
                if ($discardNum >= 10)
                {
                    $taskUpdate['is_lock_receiving'] = 1; // 当前任务是否导致账号接单资格冻结 1=>冻结 0=>不冻结
                }
                $zyhsAstrTasksModel->UpdateData($taskId, $this->astrInfo['id'], $taskUpdate);
                if ($discardNum >= 10)
                {   // 冻结 准有好事-问答接单资格  3天
                    (new Zlcr3ConsultAccount())->pauseAstrQuestionAnswer($this->consultAccountInfo, $this->request->time() + 259200, '3天内弃答10次，账号封禁3天');
                    // 给占星师发冻结消息
                    (new ZlcrAstrMessage())->add($questionInfo['astr_id'], [
                        'status' => 0,
                        'is_read' => 0,
                        'astr_id' => $questionInfo['astr_id'],
                        'type' => 9, // 默认消息
                        'title' => '问答接单封禁通知',
                        'content' => '账号封禁通知，因你3天内超10次弃答问答问题，问答接单资格冻结3天处理，3天后自动解封，如有疑问请微信联系。',
                        'target' => 'local',
                        'link' => 'empty',
                        'create_time' => $this->request->time(),
                    ]);
                }
                // 释放 占星师问题锁
                $zyhsUserQuestionModel->astrReceivingUnLock($zyhsTaskInfo['qid']);

                return show(config('code.success'), '弃答成功');
            } else
            {
                return show(config('code.error'), '服务异常，请刷新后重新操作～');
            }
        }
    }

    /**
     * 问题详情
     */
    public function questionInfo()
    {
        $taskId = input('task_id/d', '');
        $appType = input('app_type/d', 1);  // 1=>准了 2=>准有好事

        if (!in_array($appType, [1, 2], true) || empty($taskId))
        {
            return show(config('code.error'), '请求异常，请稍后再试～');
        }

        if ($appType === 1)
        {
            return $this->zhunleQuestionInfo($taskId);
        } else
        {
            return $this->zyhsQuestionInfo($taskId);
        }
    }

    /**
     * 准了 - 问答详情
     */
    private function zhunleQuestionInfo(int $taskId)
    {
        $astrTaskModel = new Zlcr2AstrTasks();
        $astrModel = new ZlcrAstr();
        $addQuestionModel = new Zlcr2UserAddQuestion();

        $is_manage = false;// 是否是 后台查看的问题内容
        $app_type = $this->headers['app-type'];
        if (strpos($app_type, 'manage') !== false && (int)$taskId > 999999999)
        {
            $is_manage = true;
        }

        if ($is_manage)
        {
            $qid = $taskId;
            $taskInfo = null;
        } else
        {
            $taskInfo = $astrTaskModel->getInfoById($taskId);
            if (!$taskInfo || $taskInfo['astr_id'] !== $this->astrInfo['id'])
            {
                if (strpos($app_type, 'manage') === false)
                {// 不是后台查看的占星师内容
                    return show(config('code.error'), '服务异常，问题不存在');
                }
            }
            $qid = $taskInfo['qid'];
        }

        $questionModel = new Zlcr2UserQuestion();
        $questionInfo = $questionModel->getInfoById($qid, ['astr_id', 'uid', 'question_type', 'question_extend', 'status', 'astr_receiving_time', 'question', 'question_des', 'consult_time', 'is_anonymity', 'answer_content', 'answer_duration', 'reply_time', 'question_imgs', 'gid', 'activity_discount', 'supplement_answer', 'supplement_answer_num', 'return_answer_num', 'complain_status']);

        if (!$questionModel)
        {
            return show(config('code.error'), '服务异常，问题不存在');
        }

        $userDes = '小行星神秘人';
        if ($questionInfo['is_anonymity'] !== 1)
        {
            $userInfo = (new User())->getUserinfo(['id' => $questionInfo['uid']]);
            if ($userInfo['rid'])
            {
                $recode = (new Recode())->getRecode(['id' => $userInfo['rid']]);
                if ($recode)
                {
                    $utilModel = new Util();
                    $userDes = '日' . $utilModel->recodeAstroShorthand($recode['sun']) . '月' . $utilModel->recodeAstroShorthand($recode['moon']) . '升' . $utilModel->recodeAstroShorthand($recode['asc']);
                }
            }
        }

        $userNickname = $userInfo['nickname'] ?? '匿名用户';
        $userAvatar = $userInfo['avatar'] ?? '/test/question_answer/anonymity1.png';
        $questionStatus = $questionInfo['status'];
        $questionData = null;
        switch ($questionInfo['question_type'])
        {
            case 1:
                if (isset($questionInfo['question_extend']['recode1']) && $questionInfo['question_extend']['recode1'])
                {
                    $questionData['astro_data'][] = [
                        'nickname' => $questionInfo['question_extend']['recode1']['name'],
                        'avatar' => $questionInfo['question_extend']['recode1']['avatar'],
                        'sex' => $questionInfo['question_extend']['recode1']['type'],
                        'age' => Util::getAgeByBirth($questionInfo['question_extend']['recode1']['year'], $questionInfo['question_extend']['recode1']['month'], $questionInfo['question_extend']['recode1']['day'], 2),
                    ];
                }
                if (isset($questionInfo['question_extend']['recode2']) && $questionInfo['question_extend']['recode2'])
                {
                    $questionData['astro_data'][] = [
                        'nickname' => $questionInfo['question_extend']['recode2']['name'],
                        'avatar' => $questionInfo['question_extend']['recode2']['avatar'],
                        'sex' => $questionInfo['question_extend']['recode2']['type'],
                        'age' => Util::getAgeByBirth($questionInfo['question_extend']['recode2']['year'], $questionInfo['question_extend']['recode2']['month'], $questionInfo['question_extend']['recode2']['day'], 2),
                    ];
                }
                break;
            case 2:
            case 3:
                $questionData = $questionInfo['question_extend'];
                break;
            default:
        }

        $tipDes = [
            'tip' => '',
            'time' => 0,
            'status' => 0,
            'tip1' => '',
            'type' => 1,
        ];
        $answerData = null;
        $giveUpData = null;
        $answerRule = $questionModel->answerRule($questionInfo['question_type']) ?? ['text_min' => 100, 'text_max' => 240, 'duration_min' => (Util::isOnline() ? 120 : 12), 'duration_max' => 300];
        if ($taskInfo && $taskInfo['status'] === 3)
        {
            $addQuestion = null;
            $hintDes = '已弃答';
        } elseif ($taskInfo && $taskInfo['status'] === 5)
        {
            $tipDes = [
                'tip' => '',
                'time' => 0,
                'status' => 0,
                'tip1' => '',
                'type' => 1,
            ];
            $addQuestion = null;
            $hintDes = '回复超时,任务已取消';
        } else
        {
            if ($questionInfo['status'] === 4)
            {   // 问题待解答
                $endTime = $questionInfo['astr_receiving_time'] + 1800 - $this->request->time();
                $endTime = $endTime > 0 ? $endTime : 0;
                $goodInfo = Util::getZhunleQuestionAnswerConfig();
                $oldPrice = (float)(sprintf('%.2f', $goodInfo[$questionInfo['gid']]['price'] * $astrModel->getAstrQuestionAnswerProportion($taskInfo['create_time'], $questionInfo['question_type'], $taskInfo['qa_level'])));
                $price = (float)(sprintf("%.2f", $oldPrice * $questionInfo['activity_discount']));
                // 扣除手续费及营业税费
                $price = Util::getAfterTaxAmount($price);
                $hintBottomBuyBar = '完成作答且通过抽查可得' . $price . '元';
                // 接单5分钟内
                if ($questionInfo['astr_receiving_time'] + 300 > $this->request->time())
                {
                    // 获取已弃答次数
                    $discardNum = $astrTaskModel->getAstrDiscardQuestionNumByToday($this->astrInfo['id']);
                    $giveUpData = [
                        'all_num' => 3,
                        'left_num' => $discardNum,
                        'hint' => '3天内弃答超10次冻结接单资格3天，',
                        'toast' => '如果3天内，弃答超10次，所有问答接单资格将被冻结3日，当前已弃答' . $discardNum . '次。',
                    ];
                }

                $tipDes = [
                    'tip' => '规定回答时间还剩：',
                    'time' => $endTime,
                    'status' => 1,
                    'tip1' => '问题回复超时，已取消',
                    'type' => 1,
                ];
            } elseif ($questionInfo['status'] === 8)
            {   // 追问待解答
                $hintBottomBuyBar = '回复追问';
                $answerRule = [
                    'text_min' => 30,
                    'text_max' => 150,
                    'duration_min' => 20,
                    'duration_max' => 300,
                ];
            } elseif ($questionInfo['status'] === 5)
            {
                $tipDes = [
                    'tip' => '等待用户追问',
                    'time' => 0,
                    'status' => 0,
                    'tip1' => '',
                    'type' => 1,
                ];
                if ($questionInfo['complain_status'] === 0 && $questionInfo['reply_time'] + 3600 > $this->request->time() && empty($questionInfo['supplement_answer']))
                {
                    // 未被申诉过  且  回答后一小时以内  且 为进行过任何补充回答
                    if (isset($questionInfo['question_extend']['version']) && Util::CheckAppVersion('2.9.4', $questionInfo['question_extend']['version']) !== '小')
                    {   // 用户版本2.9.4版本及以上 且没有追问的订单
                        if ($addQuestionModel->getQuestionAddQuestionNum($qid) === 0)
                        {
                            // 可进行 补充回复
                            $status25Des = '仅允许补充一次，非强制要求';
                            $questionStatus = 25;
                            $answerRule['text_min'] = $answerRule['text_min'] > 50 ? 50 : $answerRule['text_min'];
                            $hintBottomBuyBar = '补充回答';
                        }
                    }
                }

            } elseif ($questionInfo['status'] === 6)
            {
                $tipDes = [
                    'tip' => '任务已完成',
                    'time' => 0,
                    'status' => 0,
                    'tip1' => '',
                    'type' => 1,
                ];
            }

            if ($questionInfo['answer_content'])
            {
                $answerData[] = [
                    'nickname' => $this->astrInfo['nickname'],
                    'avatar' => $this->astrInfo['avatar'],
                    'create_time' => Util::timeToStr($questionInfo['reply_time']),  // 回复时间
                    'content' => $questionInfo['answer_content'],
                    'duration' => $questionInfo['answer_duration'],
                    'type_des' => '回答',
                ];
                if ($questionInfo['supplement_answer'])
                {
                    foreach ($questionInfo['supplement_answer'] as $supplementAnswerItem)
                    {
                        $answerData[] = [
                            'nickname' => $this->astrInfo['nickname'],
                            'avatar' => $this->astrInfo['avatar'],
                            'create_time' => Util::timeToStr($supplementAnswerItem['create_time']),  // 回复时间
                            'content' => $supplementAnswerItem['answer_content'],
                            'duration' => $supplementAnswerItem['answer_duration'],
                            'type_des' => $supplementAnswerItem['type'] === 1 ? '补充回答' : '申诉补充回答',
                        ];
                    }
                }
            }
            $addQuestionList = $addQuestionModel->getQuestionAddQuestionInfo($qid);

            $addQuestionData = [];
            $addQuestionSatatus = [
                2 => 1,
                4 => 1,
                5 => 2,
                6 => 3,
            ];
            foreach ($addQuestionList as $addQuestionItem)
            {
                if (in_array($addQuestionItem['status'], [7, 8], true))
                {
                    continue;
                }
                $addQuestionAnswerData = [];
                if ($addQuestionItem['reply_type'] === 1 && $addQuestionItem['status'] === 4)
                {
                    $addQuestionAnswerData[] = [
                        'nickname' => $this->astrInfo['nickname'],
                        'avatar' => $this->astrInfo['avatar'],
                        'create_time' => Util::timeToStr($addQuestionItem['reply_time']),  // 回复时间
                        'content' => $addQuestionItem['answer_content'],
                        'duration' => $addQuestionItem['answer_duration'],
                        'type_des' => '',
                    ];
                    if (isset($addQuestionItem['supplement_answer']))
                    {
                        foreach ($addQuestionItem['supplement_answer'] as $addQuestionSupplementAnswerItem)
                        {
                            $addQuestionAnswerData[] = [
                                'nickname' => $this->astrInfo['nickname'],
                                'avatar' => $this->astrInfo['avatar'],
                                'create_time' => Util::timeToStr($addQuestionSupplementAnswerItem['create_time']),  // 回复时间
                                'content' => $addQuestionSupplementAnswerItem['answer_content'],
                                'duration' => $addQuestionSupplementAnswerItem['answer_duration'],
                                'type_des' => '申诉追问补充：',
                            ];
                        }
                    }
                }

                $addQuestionData[] = [
                    'id' => $addQuestionItem['id'],
                    'nickname' => $userNickname,
                    'avatar' => $userAvatar,
                    'create_time' => Util::timeToStr($addQuestionItem['pay_time']),
                    'question' => $addQuestionItem['question'],
                    'status' => $addQuestionSatatus[$addQuestionItem['status']],
                    'status_des' => $addQuestionSatatus[$addQuestionItem['status']] === 2 ? '该追问已取消' : '',
                    'answer_data' => $addQuestionAnswerData,
                ];

                if ($addQuestionItem['status'] === 2)
                {   // 待解答
                    $endTime = Util::getToAnswerTime($addQuestionItem['pay_time']);
                    if ($endTime < 0)
                    {   // 超时
                        $tipDes = [
                            'tip' => '追问回复已超时：',
                            'time' => $endTime * -1,
                            'status' => 2,
                            'tip1' => '',
                            'type' => 1,
                        ];
                    } else
                    {   // 未超时
                        $tipDes = [
                            'tip' => '追问回复时间还剩：',
                            'time' => $endTime,
                            'status' => 1,
                            'tip1' => $addQuestionItem['order_num'] ? '追问回复超时，已取消' : '追问回复已超时',
                            'type' => $addQuestionItem['order_num'] ? 1 : 2,
                        ];
                    }
                }

                if ($addQuestionItem['status'] === 6 || $addQuestionItem['reply_type'] === 2)
                {   // 后台介入
                    $hintDes2 = '追问回复超时，任务收益已扣除。';
                    $tipDes = [
                        'tip' => '追问回复已超时',
                        'time' => 0,
                        'status' => 0,
                        'tip1' => '',
                        'type' => 1,
                    ];
                    continue;
                }
            }
            $addQuestionEarning = $taskInfo ? $questionModel->getAddquestionEarning($questionInfo['gid'], $taskInfo['qa_level'], $taskInfo['create_time']) : $questionModel->getAddquestionEarning($questionInfo['gid'], 1, 0);
            $addQuestion = [
                'hint' => '用户收到回复后48小时内可追问，预估每条' . $addQuestionEarning . '元',    //
                'list' => $addQuestionData,
            ];

            if ($taskInfo && ($taskInfo['status'] === 4 || $taskInfo['status'] === 7))
            {
                $appealInfo = (new ZlcrAppeal())->where(['type' => 3, 'qid' => $qid])->order('id desc')->find();
                $hintDes2 = '回答被用户申诉，平台已判定回答违规，如有疑问请联系官方';
                if ($appealInfo['astr_msg'])
                {
                    $hintDes2 .= "\r\n判断理由：" . $appealInfo['astr_msg'];
                }
                $tipDes = [
                    'tip' => '任务已结束',
                    'time' => 0,
                    'status' => 0,
                    'tip1' => '',
                    'type' => 1,
                ];
            }

            if ($taskInfo && $taskInfo['status'] === 2 && $taskInfo['lock_earning'] === 1)
            {
                $hintDes2 = '本任务收益已扣除，如有疑问请联系官方';
                $tipDes = [
                    'tip' => '任务已结束',
                    'time' => 0,
                    'status' => 0,
                    'tip1' => '',
                    'type' => 1,
                ];
            }

            if ($questionInfo['status'] === 20)
            {
                // 退回重答
                $appealInfo = (new ZlcrAppeal())->where(['type' => 3, 'qid' => $qid])->order('id desc')->find();
                if ($appealInfo['status'] == 4)
                {
                    // 答案重答
                    $hintBottomBuyBar = '申诉回答补充';
                } else
                {
                    // 补充重答
                    $answerRule = [
                        'text_min' => 30,
                        'text_max' => 150,
                        'duration_min' => 20,
                        'duration_max' => 300,
                    ];
                    $hintBottomBuyBar = '申诉追问补充';
                }
                $returnAnswerEndTime = $appealInfo['update_time'] + 21600 - time();
                $hintDes3 = '本次内容补充时间剩余：' . Sec2Time($returnAnswerEndTime);
                if ($appealInfo['astr_msg'])
                {
                    $hintDes3 .= "\r\n补充建议：" . $appealInfo['astr_msg'];
                }
                $hintGiveUpComplainSupplement = '放弃重答会使订单进入退款流程，本单收益将流失。是否确认放弃？';
            }
            if ($questionInfo['status'] === 21)
            {
                $questionStatus = 7;
            }
        }

        $resData = [
            'nickname' => $userNickname,
            'avatar' => $userAvatar,
            'create_time' => Util::timeToStr($questionInfo['consult_time']),  // 咨询时间
            'user_des' => $userDes,
            'question' => $questionInfo['question'],
            'question_des' => $questionInfo['question_des'],
            'question_type' => $questionInfo['question_type'],
            'status' => $questionStatus,
            'status_25_des' => $status25Des ?? '',
            'question_data' => $questionData,
            'tip_des' => $tipDes,
            'answer_data' => $answerData,
            'add_question' => $addQuestion,
            'answer_rule' => $answerRule,
            'photo_list' => $questionInfo['question_imgs'],
            'hint_des' => $hintDes ?? '',
            'hint_bottom_buy_bar' => $hintBottomBuyBar ?? '',
            'give_up_data' => $giveUpData,
            'hint_des2' => $hintDes2 ?? '',
            'hint_des3' => $hintDes3 ?? '',
            'hint_give_up_complain_supplement' => $hintGiveUpComplainSupplement ?? '', //
            'qid' => $qid,
        ];

        return show(config('code.success'), '请求成功', $resData);
    }

    /**
     * 准有好事 - 问答详情
     */
    private function zyhsQuestionInfo(int $taskId)
    {
        $zyhsAstrTasksModel = new ZyhsAstrTasks();
        $questionModel = new ZyhsUserQuestion();
        $zlcr3ConsultAccountModel = new Zlcr3ConsultAccount();
        $zyhsUserAddQuestionModel = new ZyhsUserAddQuestion();

        $taskInfo = $zyhsAstrTasksModel->getInfoById($taskId);
        if (!$taskInfo || $taskInfo['astr_id'] !== $this->astrInfo['id'])
        {
            return show(config('code.error'), '服务异常，问题不存在');
        }
        $qid = $taskInfo['qid'];
        $questionInfo = $questionModel->getInfoById($qid);

        $userDes = '小行星神秘人';
        $userInfo = (new ZyhsUser())->getInfoById($questionInfo['uid']);
        if ($userInfo['rid'])
        {
            $recode = (new ZyhsRecode())->getInfoById($userInfo['rid']);
            if ($recode)
            {
                $utilModel = new Util();
                $userDes = '日' . $utilModel->recodeAstroShorthand($recode['sun']) . '月' . $utilModel->recodeAstroShorthand($recode['moon']) . '升' . $utilModel->recodeAstroShorthand($recode['asc']);
            }
        }
        $nickname = $userInfo['nickname'];
        $avatar = $userInfo['avatar'];

        $questionData = [
            'astro_data' => [],
            'dice_data' => null,
            'tarot_data' => null,
        ];
        switch ($questionInfo['question_type'])
        {
            case 1:
                if (isset($questionInfo['question_extend']['recode1']) && $questionInfo['question_extend']['recode1'])
                {
                    $questionData['astro_data'][] = [
                        'nickname' => $questionInfo['question_extend']['recode1']['name'],
                        'avatar' => $questionInfo['question_extend']['recode1']['avatar'],
                        'sex' => $questionInfo['question_extend']['recode1']['type'],
                        'age' => Util::getAgeByBirth($questionInfo['question_extend']['recode1']['year'], $questionInfo['question_extend']['recode1']['month'], $questionInfo['question_extend']['recode1']['day'], 2),
                    ];
                }
                if (isset($questionInfo['question_extend']['recode2']) && $questionInfo['question_extend']['recode2'])
                {
                    $questionData['astro_data'][] = [
                        'nickname' => $questionInfo['question_extend']['recode2']['name'],
                        'avatar' => $questionInfo['question_extend']['recode2']['avatar'],
                        'sex' => $questionInfo['question_extend']['recode2']['type'],
                        'age' => Util::getAgeByBirth($questionInfo['question_extend']['recode2']['year'], $questionInfo['question_extend']['recode2']['month'], $questionInfo['question_extend']['recode2']['day'], 2),
                    ];
                }
                break;
            case 2:
                $questionData['dice_data'] = $questionInfo['question_extend']['dice_data'] ?? null;
                break;
            case 3:
                $questionData['tarot_data'] = $questionInfo['question_extend']['tarot_data'] ?? null;
                break;
            default:
        }

        $tipDes = [
            'tip' => '',
            'time' => 0,
            'status' => 0,
            'tip1' => '',
            'type' => 1,
        ];
        if ($taskInfo['answer_content'])
        {
            $answerData[] = [
                'nickname' => $this->astrInfo['nickname'],
                'avatar' => $this->astrInfo['avatar'],
                'create_time' => Util::timeToStr($taskInfo['reply_time']),  // 回复时间
                'content' => $taskInfo['answer_content'],
                'duration' => $taskInfo['answer_duration'],
                'type_des' => '回答',
            ];
        }
        $giveUpData = null;
        $answerRule = $questionModel->answerRule($questionInfo['question_type']);
        // 状态
        //  1=>待解答【已接单】
        //  2=>已弃答
        //  3=>已解答【可追问48小时后自动完成】
        //  4=>已解答【追问回复超时，不可追问48小时后自动完成】
        //  5=>追问待解答
        //  6=>已完成
        //  7=>答案回复超时
        //  8=>已完成且收益扣除【用户申述已取消】
        //  9=>已完成且收益扣除【追问回复超时未完成】
        switch ($taskInfo['status'])
        {
            case 1: // 待解答
                $questionStatus = 4;
                $endTime = $taskInfo['create_time'] + 1800 - $this->request->time();
                $endTime = $endTime > 0 ? $endTime : 0;
                $proportionData = $zlcr3ConsultAccountModel->getQuestionAnswerPercent();
                $price = (float)(sprintf("%.2f", $questionInfo['good_amount'] / $questionInfo['consult_num'] / 10 * $proportionData['question']));
                // 扣除手续费及营业税费
                $price = Util::getAfterTaxAmount($price);
                $hintBottomBuyBar = '完成作答且通过抽查可得' . $price . '元';
                // 接单5分钟内
                if ($taskInfo['create_time'] + 300 > $this->request->time())
                {
                    // 获取已弃答次数
                    $discardNum = $zyhsAstrTasksModel->getAstrDiscardQuestionNumByToday($this->astrInfo['id']);
                    $giveUpData = [
                        'all_num' => 3,
                        'left_num' => $discardNum,
                        'hint' => '3天内弃答超10次冻结接单资格3天，',
                        'toast' => '如果3天内，弃答超10次，所有问答接单资格将被冻结3日，当前已弃答' . $discardNum . '次。',
                    ];
                }
                $tipDes = [
                    'tip' => '规定回答时间还剩：',
                    'time' => $endTime,
                    'status' => 1,
                    'tip1' => '问题回复超时，已取消',
                    'type' => 1,
                ];
                break;
            case 2: // 已弃答
                $hintDes = '已弃答';
                $questionStatus = 9;
                break;
            case 3: // 已解答【可追问48小时后自动完成】
            case 4: // 已解答【可追问48小时后自动完成】
                $tipDes['tip'] = '等待用户追问';
                $questionStatus = 5;
                break;
            case 5: // 已追问待解答
                $hintBottomBuyBar = '回复追问';
                $answerRule = [
                    'text_min' => 30,
                    'text_max' => 150,
                    'duration_min' => 20,
                    'duration_max' => 300,
                ];
                $questionStatus = 8;
                break;
            case 6: // 已完成
                $tipDes['tip'] = '任务已完成';
                $questionStatus = 6;
                break;
            case 7: // 答案回复超时
                $hintDes = '回复超时,任务已取消';
                $questionStatus = 9;
                break;
            default: // 8=>已完成且收益扣除【用户申述已取消】 9=>已完成且收益扣除【追问回复超时未完成】
                $questionStatus = 7;
        }

        $addQuestionList = $zyhsUserAddQuestionModel->getQuestionAddQuestionInfo($taskId);
        $addQuestionData = [];
        $addQuestionSatatus = [
            2 => 1,
            4 => 1,
            5 => 2,
            6 => 3,
        ];
        foreach ($addQuestionList as $addQuestionItem)
        {
            if (in_array($addQuestionItem['status'], [7, 8], true))
            {
                continue;
            }

            $addQuestionAnswerData = [];
            if ($addQuestionItem['status'] === 4)
            {
                $addQuestionAnswerData[] = [
                    'nickname' => $this->astrInfo['nickname'],
                    'avatar' => $this->astrInfo['avatar'],
                    'create_time' => Util::timeToStr($addQuestionItem['reply_time']),  // 回复时间
                    'content' => $addQuestionItem['answer_content'],
                    'duration' => $addQuestionItem['answer_duration'],
                    'type_des' => '',
                ];
            }

            $addQuestionData[] = [
                'id' => $addQuestionItem['id'],
                'nickname' => $nickname,
                'avatar' => $avatar,
                'create_time' => Util::timeToStr($addQuestionItem['pay_time']),
                'question' => $addQuestionItem['question'],
                'status' => $addQuestionSatatus[$addQuestionItem['status']],
                'status_des' => $addQuestionSatatus[$addQuestionItem['status']] === 2 ? '该追问已取消' : '',
                'answer_data' => $addQuestionAnswerData,
            ];

            if ($addQuestionItem['status'] === 2)
            {   // 待解答
                $endTime = Util::getToAnswerTime($addQuestionItem['pay_time']);
                if ($endTime < 0)
                {   // 超时
                    $tipDes = [
                        'tip' => '追问回复已超时：',
                        'time' => $endTime * -1,
                        'status' => 2,
                        'tip1' => '',
                        'type' => 1,
                    ];
                } else
                {   // 未超时
                    $tipDes = [
                        'tip' => '追问回复时间还剩：',
                        'time' => $endTime,
                        'status' => 1,
                        'tip1' => $addQuestionItem['order_num'] ? '追问回复超时，已取消' : '追问回复已超时',
                        'type' => $addQuestionItem['order_num'] ? 1 : 2,
                    ];
                }
            }
        }

        if (in_array($taskInfo['status'], [1, 3, 4, 5, 6, 8, 9, 10], true))
        {
            $addQuestionEarning = $questionModel->getAddquestionEarning($questionInfo['gid']);
            $addQuestion = [
                'hint' => '用户收到回复后48小时内可追问，预估每条' . $addQuestionEarning . '元',
                'list' => $addQuestionData,
            ];
        } else
        {
            $addQuestion = null;
        }


        $resData = [
            'nickname' => $nickname,
            'avatar' => $avatar,
            'create_time' => Util::timeToStr($questionInfo['create_time']),  // 咨询时间
            'user_des' => $userDes,
            'question' => '',
            'question_des' => $questionInfo['question'],
            'question_type' => $questionInfo['question_type'],
            'status' => $questionStatus,
            'status_25_des' => $status25Des ?? '',
            'question_data' => $questionData,
            'tip_des' => $tipDes,
            'answer_data' => $answerData ?? null,
            'add_question' => $addQuestion,
            'answer_rule' => $answerRule,
            'photo_list' => [],
            'hint_des' => $hintDes ?? '',
            'hint_bottom_buy_bar' => $hintBottomBuyBar ?? '',
            'give_up_data' => $giveUpData,
            'hint_des2' => $hintDes2 ?? '',
            'hint_des3' => $hintDes3 ?? '',
            'hint_give_up_complain_supplement' => '', //
            'qid' => $qid,
        ];

        return show(config('code.success'), '请求成功', $resData);
    }

    /**
     * 解答问题 已完成
     */
    public function toAnswer()
    {
        $taskId = input('task_id/d', '');
        $type = input('type/d', 0); // 回答类型【1=>语音,2=>文字】
        $content = trim(input('content/s', ''));    // 答案内容【语音回答为视频地址】
        $duration = input('duration/d', 0);
        $appType = input('app_type/d', 0);

        if (empty($content))
        {
            return show(config('code.error'), '答案不能为空');
        }
        if (!in_array($type, [1, 2], true))
        {
            return show(config('code.error'), '答案类型异常，请稍后再试～');
        }
        if (!in_array($appType, [1, 2], true))
        {
            return show(config('code.error'), '请求异常，任务类型不存在～');
        }
        if (Util::commentCheck($this->astrInfo['id'], ['action' => 'toAnswer', 'task_id' => $taskId, 'type' => $type, 'content' => $content, 'duration' => $duration, 'app_type' => $appType], 5))
        {
            return show(config('code.error'), '操作频繁，请稍后再试～');
        }
        // 阿里检测
        if ($type === 2)
        {
            $res = AliyunFilterWord::checkText($content, 'question_astro');
            if ($res)
            {
                return show(config('code.error'), '当前回复中有违规词汇请重新核实');
            }
        }
        $zyhsConsultChatRecordDetailsModel = new ZyhsConsultChatRecordDetails();
        if ($appType === 1)
        {   // 准了 - 问答 解答问题
            $astrTaskModel = new Zlcr2AstrTasks();
            $taskInfo = $astrTaskModel->getInfoById($taskId);
            if (!$taskInfo || $taskInfo['astr_id'] !== $this->astrInfo['id'])
            {
                return show(config('code.error'), '服务异常，问题不存在');
            }
            if ($taskInfo['status'] !== 1)
            {
                return show(config('code.error'), '任务状态异常，请稍后再试～');
            }
            $qid = $taskInfo['qid'];
            $questionModel = new Zlcr2UserQuestion();
            $questionInfo = $questionModel->getInfoById($qid, []);
            if ($questionInfo['astr_id'] !== $this->astrInfo['id'])
            {
                return show(config('code.error'), '服务异常，问题不存在');
            }
            if (!in_array($questionInfo['status'], [4, 8], true))
            {
                return show(config('code.error'), '问题状态异常，请稍后再试～');
            }
            if ($questionInfo['status'] === 4)
            {   // 回复问题
                $answerRule = $questionModel->answerRule($questionInfo['question_type']);
            } else
            {   // 回复追问
                $answerRule = [
                    'text_min' => 30,
                    'text_max' => 150,
                    'duration_min' => 20,
                    'duration_max' => 300,
                ];
            }
            if ($type === 1)
            {
                if ($duration < $answerRule['duration_min'])
                {
                    return show(config('code.error'), '语音至少录制' . $answerRule['duration_min'] . '秒');
                }
                if ($duration > $answerRule['duration_max'])
                {
                    return show(config('code.error'), '语音最多录制' . $answerRule['duration_max'] . '秒');
                }
            } else
            {
                if (mb_strlen($content) < $answerRule['text_min'])
                {
                    return show(config('code.error'), '答案至少' . $answerRule['text_min'] . '字');
                }
                if (mb_strlen($content) > $answerRule['text_max'])
                {
                    return show(config('code.error'), '答案最多' . $answerRule['text_max'] . '字');
                }
            }
            try
            {
                if ($questionInfo['status'] === 4)
                {   // 回复问题
                    $questionModel->UpdateData($qid, [
                        'status' => 5,
                        'is_read' => 0,
                        'uid' => $questionInfo['uid'],
                        'answer_content' => $content,
                        'answer_duration' => $type === 1 ? $duration : 0,
                        'reply_time' => $this->request->time(),
                    ]);
                    // 删除当前进行中任务
                    Cache::rm('question_answer:is_underway:' . $this->astrInfo['id']); // 删除 占星师当前有进行中的任务
                    if (isset($questionInfo['question_extend']['version']) && Util::checkAppVersion('2.15.0', $questionInfo['question_extend']['version']) !== '小')
                    {   // 发送与用户咨询消息
                        $zyhsConsultChatRecordDetailsModel->QuestionAnswerSendConsultMsgToUser(2, $questionInfo['uid'], $this->astrInfo, [
                            'app_type' => 2,
                            'uid' => $questionInfo['uid'],
                            'astr_id' => $this->astrInfo['id'],
                            'type' => 1,    //  1=>APP消息 2=>用户发送消息
                            'title' => '',
                            'content' => '', // 提问问题
                            'data_type' => 6,   // 数据类型  1=>普通消息  2=>图片  3=>语音咨询消息  4=>咨询问题  5=>咨询问题答案 6=>问答悬赏问题回复 7=>问答悬赏追问已回复
                            'extend' => ['intercept_tips' => '', 'qa_data' => ['qid' => $qid, 'task_id' => $taskId]],  //  语音咨询消息 ｜ 图片信息 | 内容拦截信息 | qa_data=>问答问题详情
                            'pid' => 0, // 待更新
                            'create_time' => $this->request->time(),
                        ]);
                    }
                    // 发送短信通知
                    $userInfo = (new User())->getUserinfo(['id' => $questionInfo['uid']]);
                    if ($userInfo && $userInfo['tel'])
                    {
                        Util::sendHySms([$userInfo['tel']], '', 52341, ['order_num' => $questionInfo['order_num']]);
                    }
                    // 消息中心添加信息
                    $messageData = [
                        'status' => 0,
                        'is_read' => 0,
                        'range' => $questionInfo['uid'],
                        'type' => 2,
                        'reid' => 0,
                        'cid' => 4,//
                        'title' => '问答回复通知',
                        'content' => '你开启的悬赏问答，订单编号：' . $questionInfo['order_num'] . '咨询师已回复，请注意查看，你可以在48小时内追问占星师。',// 消息中心跳转地址
                        'link' => "question_detail?qid={$qid}&need_auth=0",
                        'target' => 'local',
                        'create_time' => $this->request->time(),
                    ];
                    (new MessageCenter())->pushMessage($questionInfo['uid'], $messageData);
                    $pushData = ['action' => 'extend', 'target' => 'local', 'link' => "question_detail?qid={$qid}&need_auth=0"];
                    // PUSH推送报告首页
                    (new Push())->pushUserMsg($questionInfo['uid'], '你开启的悬赏问答，订单编号：' . $questionInfo['order_num'] . '咨询师已回复，请注意查看，你可以在48小时内追问占星师。', $pushData);

                    // 添加问题完成 队列
                    // 发送 问答完成检测 队列 48小时后回答
                    Util::queuePush('question_answer_question_success_check', ['task_id' => $taskId], 172800);
                    // 追问通知检测 40小时后还未追问
                    Util::queuePush('question_answer_user_add_question_notify', ['qid' => $qid], 144000);
                } else
                {   // 回复追问
                    $addQuestionModel = new Zlcr2UserAddQuestion();
                    $addQuestionInfo = $addQuestionModel->getAddQuestionByNotAnswer($qid);
                    if (!$addQuestionInfo)
                    {
                        return show(config('code.error'), '服务异常，没有待解答的追问～');
                    }
                    // 追问回复
                    $addQuestionModel->UpdateData($qid, $addQuestionInfo['id'], [
                        'status' => 4,
                        'answer_content' => $content,
                        'answer_duration' => $type === 1 ? $duration : 0,
                        'reply_time' => $this->request->time(),
                        'reply_type' => 1,
                        'reply_uid' => $this->astrInfo['id'],
                    ]);

                    // 更新问题状态至待追问
                    $questionModel->UpdateData($qid, [
                        'status' => 5,
                        'is_read' => 0,
                        'uid' => $questionInfo['uid'],
                    ]);
                    // 给追问用户提示有新回复
                    (new Zlcr2QuestionUserView())->questionNewAnswer($qid);
                    if (isset($questionInfo['question_extend']['version']) && Util::checkAppVersion('2.15.0', $questionInfo['question_extend']['version']) !== '小')
                    {   // 发送与用户咨询消息
                        $zyhsConsultChatRecordDetailsModel->QuestionAnswerSendConsultMsgToUser(2, $questionInfo['uid'], $this->astrInfo, [
                            'app_type' => 2,
                            'uid' => $questionInfo['uid'],
                            'astr_id' => $this->astrInfo['id'],
                            'type' => 1,    //  1=>APP消息 2=>用户发送消息
                            'title' => '',
                            'content' => '', // 提问问题
                            'data_type' => 7,   // 数据类型  1=>普通消息  2=>图片  3=>语音咨询消息  4=>咨询问题  5=>咨询问题答案 6=>问答悬赏问题回复 7=>问答悬赏追问已回复
                            'extend' => ['intercept_tips' => '', 'qa_data' => ['qid' => $qid, 'task_id' => $taskId]],  //  语音咨询消息 ｜ 图片信息 | 内容拦截信息 | qa_data=>问答问题详情
                            'pid' => 0, // 待更新
                            'create_time' => $this->request->time(),
                        ]);
                    }
                    if ($questionInfo['reply_time'] + 172800 < $this->request->time())
                    {   // 不在追问时间范围内    172800=60*60*24*2 48小时
                        Util::queuePush('question_answer_question_success_check', ['task_id' => $taskId], 5);
                    }
                    // 发送短信通知
                    $userInfo = (new User())->getUserinfo(['id' => $questionInfo['uid']]);
                    if ($userInfo && $userInfo['tel'])
                    {
                        Util::sendHySms([$userInfo['tel']], '', 52349, ['order_num' => $questionInfo['order_num']]);
                    }
                    // 消息中心添加信息
                    $messageData = [
                        'status' => 0,
                        'is_read' => 0,
                        'range' => $questionInfo['uid'],
                        'type' => 2,
                        'reid' => 0,
                        'cid' => 4,//
                        'title' => '问答追问回复通知',
                        'content' => '你开启的悬赏问答追问，订单编号：' . $questionInfo['order_num'] . '咨询师已回复，请注意查看。',// 消息中心跳转地址
                        'link' => "question_detail?qid={$qid}&need_auth=0",
                        'target' => 'local',
                        'create_time' => $this->request->time(),
                    ];
                    (new MessageCenter())->pushMessage($questionInfo['uid'], $messageData);
                    $pushData = ['action' => 'extend', 'target' => 'local', 'link' => "question_detail?qid={$qid}&need_auth=0"];
                    // PUSH推送报告首页
                    (new Push())->pushUserMsg($questionInfo['uid'], '你开启的悬赏问答追问，订单编号：' . $questionInfo['order_num'] . '咨询师已回复，请注意查看。', $pushData);
                }
            }
            catch (\Exception $e)
            {
                Log::write(($questionInfo['status'] === 4 ? '问答' : '问答追问') . '回复异常：' . $e->getMessage() . "；错误文件「{$e->getFile()}」错误行数「{$e->getLine()}」", 'error');
                return show(config('code.error'), '服务异常，请稍后再试～');
            }
        } else
        {   // 准有好事 - 问答 解答问题
            $zyhsAstrTasksModel = new ZyhsAstrTasks();
            $zyhsUserQuestionModel = new ZyhsUserQuestion();
            $taskInfo = $zyhsAstrTasksModel->getInfoById($taskId);
            if (!$taskInfo || $taskInfo['astr_id'] !== $this->astrInfo['id'])
            {
                return show(config('code.error'), '服务异常，问题不存在');
            }
            if (!in_array($taskInfo['status'], [1, 5], true))
            {   // 1问题待解答 5追问待解答
                return show(config('code.error'), '任务状态异常，请稍后再试～');
            }
            $qid = $taskInfo['qid'];
            $zyhsQuestionInfo = $zyhsUserQuestionModel->getInfoById($qid);
            if ($taskInfo['status'] === 1)
            {   // 回答问题
                $answerRule = $zyhsUserQuestionModel->answerRule($zyhsQuestionInfo['question_type']);
            } else
            {   // 解答追问问题
                $answerRule = [
                    'text_min' => 30,
                    'text_max' => 150,
                    'duration_min' => 20,
                    'duration_max' => 300,
                ];
            }
            if ($type === 1)
            {
                if ($duration < $answerRule['duration_min'])
                {
                    return show(config('code.error'), '语音至少录制' . $answerRule['duration_min'] . '秒');
                }
                if ($duration > $answerRule['duration_max'])
                {
                    return show(config('code.error'), '语音最多录制' . $answerRule['duration_max'] . '秒');
                }
            } else
            {
                if (mb_strlen($content) < $answerRule['text_min'])
                {
                    return show(config('code.error'), '答案至少' . $answerRule['text_min'] . '字');
                }
                if (mb_strlen($content) > $answerRule['text_max'])
                {
                    return show(config('code.error'), '答案最多' . $answerRule['text_max'] . '字');
                }
            }
            try
            {
                if ($taskInfo['status'] === 1)
                {   // 回答问题
                    $answerData = [
                        'status' => 3,
                        'answer_content' => $content,
                        'answer_duration' => $type === 1 ? $duration : 0,
                        'reply_time' => $this->request->time(),
                        'update_time' => $this->request->time(),
                    ];
                    $zyhsAstrTasksModel->UpdateData($taskId, $this->astrInfo['id'], $answerData);
                    // 更新已接单 任务列表
                    $receivingTasks = $zyhsQuestionInfo['extend']['receiving_tasks'];
                    foreach ($receivingTasks as $k => $receivingTaskItem)
                    {
                        if ($taskId === (int)$receivingTaskItem['task_id'])
                        {   // 是否已回复
                            $receivingTasks[$k]['is_reply'] = 1;
                        }
                    }
                    $zyhsQuestionInfo['extend']['receiving_tasks'] = $receivingTasks;
                    $questionInfoUpdate = [
                        'extend' => $zyhsQuestionInfo['extend'],
                        'is_read' => 0,
                        'uid' => $zyhsQuestionInfo['uid'],
                        'update_time' => $this->request->time(),
                    ];
                    if ($zyhsQuestionInfo['first_reply_time'] === 0)
                    {   // 有回复
                        $questionInfoUpdate['first_reply_time'] = $this->request->time();
                    }
                    // 更新 准有好事 问答问题详情 信息更新
                    $zyhsUserQuestionModel->UpdateData($qid, $questionInfoUpdate);
                    // 发送与用户咨询消息
                    $zyhsConsultChatRecordDetailsModel->QuestionAnswerSendConsultMsgToUser(1, $zyhsQuestionInfo['uid'], $this->astrInfo, [
                        'app_type' => 1,
                        'uid' => $zyhsQuestionInfo['uid'],
                        'astr_id' => $this->astrInfo['id'],
                        'type' => 1,    //  1=>APP消息 2=>用户发送消息
                        'title' => '',
                        'content' => '', // 提问问题
                        'data_type' => 6,   // 数据类型  1=>普通消息  2=>图片  3=>语音咨询消息  4=>咨询问题  5=>咨询问题答案 6=>问答悬赏问题回复 7=>问答悬赏追问已回复
                        'extend' => ['intercept_tips' => '', 'qa_data' => ['qid' => $qid, 'task_id' => $taskId]],  //  语音咨询消息 ｜ 图片信息 | 内容拦截信息 | qa_data=>问答问题详情
                        'pid' => 0, // 待更新
                        'create_time' => $this->request->time(),
                    ]);
                    // 获取用户信息
                    $userInfo = (new ZyhsUser())->getInfoById($zyhsQuestionInfo['uid']);
                    if ($userInfo && $userInfo['tel'])
                    {   // 发送 短信通知 用户
                        Alidayu::getInstance()->zyhsMsgSmsSend(86, $userInfo['tel'], 'SMS_464380299', ['order_num' => $zyhsQuestionInfo['order_num']]);
                    }
                    // 消息中心添加信息
                    $messageData = [
                        'status' => 0,
                        'is_read' => 0,
                        'range' => $zyhsQuestionInfo['uid'],
                        'type' => 2,
                        'reid' => 0,
                        'cid' => 4,//
                        'title' => '问答回复通知',
                        'content' => '你开启的悬赏问答，订单编号：' . $zyhsQuestionInfo['order_num'] . '咨询师已回复，请注意查看，你可以在48小时内追问咨询师。',// 消息中心跳转地址
                        'link' => "question_detail?qid={$qid}&need_auth=0",
                        'target' => 'local',
                        'create_time' => $this->request->time(),
                    ];
                    (new ZyhsMessageCenter())->pushMessage($zyhsQuestionInfo['uid'], $messageData);
                    $pushData = [
                        'action' => 'extend',
                        'target' => 'local',
                        'link' => "question_detail?qid={$qid}&need_auth=0",
                        'pop_msg' => json_encode([
                            'avatar' => $this->astrInfo['avatar'],
                            'name' => $this->astrInfo['nickname'],
                            'level' => $this->consultAccountInfo['level'] ?? 1,
                            'msg' => '悬赏问题已回复',
                            'target' => 'local',
                            'link' => "question_detail?qid={$qid}&need_auth=0",
                            'astr_id' => $this->astrInfo['id'],
                        ], JSON_UNESCAPED_UNICODE),
                    ];
                    // PUSH推送报告首页
                    (new ZyhsPush())->pushUserMsg($zyhsQuestionInfo['uid'], '你开启的悬赏问答，订单编号：' . $zyhsQuestionInfo['order_num'] . '咨询师已回复，请注意查看，你可以在48小时内追问咨询师。', $pushData);
                    // 发送 问答完成检测 队列 48小时后回答
                    Util::queuePush('zyhs_question_answer_question_success_check', ['task_id' => $taskId], 172800);
                } else
                {   // 解答追问问题
                    $zyhsUserAddQuestionModel = new ZyhsUserAddQuestion();
                    $addQuestionInfo = $zyhsUserAddQuestionModel->getAddQuestionByNotAnswer($taskId);
                    if (!$addQuestionInfo)
                    {
                        return show(config('code.error'), '服务异常，没有待解答的追问～');
                    }
                    // 追问回复
                    $zyhsUserAddQuestionModel->UpdateData($addQuestionInfo['id'], [
                        'status' => 4,
                        'answer_content' => $content,
                        'answer_duration' => $type === 1 ? $duration : 0,
                        'reply_time' => $this->request->time(),
                        'astr_id' => $this->astrInfo['id'],
                    ]);
                    $questionInfoUpdate = [
                        'is_read' => 0,
                        'uid' => $zyhsQuestionInfo['uid'],
                        'update_time' => $this->request->time(),
                    ];
                    // 更新 准有好事 问答问题详情 信息更新
                    $zyhsUserQuestionModel->UpdateData($qid, $questionInfoUpdate);
                    // 更新占星师 任务信息
                    $answerData = [
                        'status' => 3,
                        'update_time' => $this->request->time(),
                    ];
                    $zyhsAstrTasksModel->UpdateData($taskId, $this->astrInfo['id'], $answerData);
                    // 发送与用户咨询消息
                    $zyhsConsultChatRecordDetailsModel->QuestionAnswerSendConsultMsgToUser(1, $zyhsQuestionInfo['uid'], $this->astrInfo, [
                        'app_type' => 1,
                        'uid' => $zyhsQuestionInfo['uid'],
                        'astr_id' => $this->astrInfo['id'],
                        'type' => 1,    //  1=>APP消息 2=>用户发送消息
                        'title' => '',
                        'content' => '', // 提问问题
                        'data_type' => 7,   // 数据类型  1=>普通消息  2=>图片  3=>语音咨询消息  4=>咨询问题  5=>咨询问题答案 6=>问答悬赏问题回复 7=>问答悬赏追问已回复
                        'extend' => ['intercept_tips' => '', 'qa_data' => ['qid' => $qid, 'task_id' => $taskId]],  //  语音咨询消息 ｜ 图片信息 | 内容拦截信息 | qa_data=>问答问题详情
                        'pid' => 0, // 待更新
                        'create_time' => $this->request->time(),
                    ]);
                    if ($taskInfo['reply_time'] + 172800 < $this->request->time())
                    {   // 不在追问时间范围内    172800=60*60*24*2 48小时
                        Util::queuePush('zyhs_question_answer_question_success_check', ['task_id' => $taskId], 5);
                    }
                    // 获取用户信息
                    $userInfo = (new ZyhsUser())->getInfoById($zyhsQuestionInfo['uid']);
                    if ($userInfo && $userInfo['tel'])
                    {   // 发送 短信通知 用户
                        Alidayu::getInstance()->zyhsMsgSmsSend(86, $userInfo['tel'], 'SMS_464325294', ['order_num' => $zyhsQuestionInfo['order_num']]);
                    }
                    // 消息中心添加信息
                    $messageData = [
                        'status' => 0,
                        'is_read' => 0,
                        'range' => $zyhsQuestionInfo['uid'],
                        'type' => 2,
                        'reid' => 0,
                        'cid' => 4,//
                        'title' => '问答追问回复通知',
                        'content' => '你开启的悬赏问答追问，订单编号：' . $zyhsQuestionInfo['order_num'] . '咨询师已回复，请注意查看。',// 消息中心跳转地址
                        'link' => "question_detail?qid={$qid}&need_auth=0",
                        'target' => 'local',
                        'create_time' => $this->request->time(),
                    ];
                    (new ZyhsMessageCenter())->pushMessage($zyhsQuestionInfo['uid'], $messageData);
                    // 向准有好事 用户发送推送消息 --------
                    $pushData = [
                        'action' => 'extend',
                        'target' => 'local',
                        'link' => "question_detail?qid={$qid}&need_auth=0",
                        'pop_msg' => json_encode([
                            'avatar' => $this->astrInfo['avatar'],
                            'name' => $this->astrInfo['nickname'],
                            'level' => $this->consultAccountInfo['level'] ?? 1,
                            'msg' => '悬赏问题追问已回复',
                            'target' => 'local',
                            'link' => "question_detail?qid={$qid}&need_auth=0",
                            'astr_id' => $this->astrInfo['id'],
                        ], JSON_UNESCAPED_UNICODE),
                    ];
                    // PUSH推送报告首页
                    (new ZyhsPush())->pushUserMsg($zyhsQuestionInfo['uid'], '你开启的悬赏问答追问，订单编号：' . $zyhsQuestionInfo['order_num'] . '咨询师已回复，请注意查看。', $pushData);
                }
            }
            catch (\Exception $e)
            {
                Log::write(__CLASS__ . ' => ' . __FUNCTION__ . '()异常：' . $e->getMessage() . '失败信息：' . $e->getFile() . ':' . $e->getLine(), 'error', true);
                return show(config('code.error'), '服务异常，请稍后再试～');
            }
        }

        return show(config('code.success'), '回复成功');
    }

    /**
     * 常见问题 已完成
     */
    public function getFaq()
    {
        $appType = input('app_type/d', 1);// 1=>准了 2=>准有好事
        if (1 === $appType)
        {
            $data = [
                [
                    'title' => '1.怎么获得问答的接单资格？',
                    'content' => "问答有4种类型的考试，3合1考试，考试通过后可获得所有类型问答的接单资格；占星咨询师考试，考试通过后会获得星盘问答的接单资格；卡牌咨询师考试，考试通过后会获得卡牌问答的接单资格；骰子咨询师考试，考试通过后会获得骰子问答的接单资格。\r\n定制报告的考试通过后，便可获得星盘问答的接单资格。",
                ],
                [
                    'title' => '2.怎么获得更高的收益？',
                    'content' => '能力分越高意味着咨询师的等级越高，越高等级的咨询师的分成比例越高。在接单任务进行过程中，严格按照规范完成任务非常关键，直接影响到你的能力分，间接影响到你的收益。',
                ],
                [
                    'title' => '3.哪些行为会扣除能力分？',
                    'content' => '任务问题超时回复、追问超时回复、评价星级过低，都会导致扣除能力分。',
                ],
                [
                    'title' => '4.哪些行为会增加能力分？',
                    'content' => '完成接单任务、获得好评、每日完成5单以上，都可以增加能力分。',
                ],
                [
                    'title' => '5.哪些行为会冻结收益？',
                    'content' => "当用户对你的回答发起申诉，平台核实申诉成立后，会冻结接单任务的收益；\r\n当追问超时未回复，官方介入后，会冻结接单任务的收益。",
                ],
                [
                    'title' => '6.哪些行为会封禁账号？',
                    'content' => "当能力分低于80分时，将自动封禁账号；\r\n当30天超过3次回复超时的情况将封禁账号；\r\n当用户申诉问题回复，平台核实申诉成立的情况下，如情节严重可能会封禁账号；\r\n当平台抽查发现存在严重违规的情况下，会封禁账号。",
                ],
            ];
        } else
        {
            $data = [
                [
                    'title' => '一、如何获得问答解答资格',
                    'content' => "准有好事咨询师全部为准有好事平台内部邀请，内部具备星盘连麦资格的咨询师将自动开启问答星盘及骰子接单权限，内部具备卡牌连麦资格的咨询师将自动开启问答卡牌接单权限，如咨询师要扩充接单权限，可通过自己团队管理者进行申请面试技能，技能通过后即可开通。",
                ],
                [
                    'title' => '二、问答回复规则',
                    'content' => "1. 准有好事问答接单后30分钟内给出回复\r\n2. 接单后如用户提问存在问题或提问方式符合，例如提问方式问骰子，但是提问问题只能通过看星盘解决，5分钟内可弃答，72小时内最多弃答超3次，第四次将封禁接单资格。\r\n3. 因问答回复后存在用户追问情况，常规时间追问需在1小时内进行回复，特殊时间（20:00-10:00时间）的追问在11:00之前回复，追问超时不回复将会扣除本订单所有收益。\r\n4. 咨询师追问的问题必须与提问问题关联，如咨询师认为追问的问题无关联，可直接申请追问违规，无责取消用户追问。",
                ],
                [
                    'title' => '三、问答回复内容要求：',
                    'content' => "因问答一次仅能提问一个问题， 如用户提问问题较多，可酌情重点回复用户第一个问题，其他问题可一语带过\r\n星盘：文字不少于300字，语音不少于3分钟\r\n卡牌：文字不少于200字，语音不少于2分钟\r\n骰子：文字不少于150字，语音不少于1分30秒\r\n以上回复内容按照标准选择文字或语音解答都可\r\n回复标准：\r\n1. 遇到用户在问答中提问多个问题的，第一个问题重点回复，其他问题简单回复或不回复皆可，不回复时需要告知用户问答一次只能问一个问题\r\n2. 星盘问题时，必须针对用户的问题进行详细的解析，并给出合理的建议，如用户问未来另一半什么时候遇到，需要告诉用户另一半具体遇到的时间、遇到的场合、另一半的个人年龄及外貌特征等，尽可能提供的详细、明了。\r\n3. 卡牌问题时，需解析各个卡牌牌都代表着什么，结合用户的问题给予解答，并提供合理的建议\r\n4. 骰子问题时，需解析各个骰子代表着什么，结合用户的问题给予解答，并提供合理的建议",
                ],
                [
                    'title' => '四、成长值加减及处罚标准：',
                    'content' => "用户评价4星+3\r\n用户评价5星+5\r\n用户评价2星-10\r\n用户评价1星-20\r\n咨询订单用户发起申诉且官方判定申诉成功-20\r\n问答接单后问题回复超时， 成长值-20\r\n问答用户追问回复超时，成长值-10\r\n30日内成长值扣除高于100，自动封禁账号\r\n30日内问答回复超时第4次，问答关闭接单资格\r\n30日内问答追问超时第4次，问答关闭接单资格",
                ],
                [
                    'title' => '五、如何获得更高的收益：',
                    'content' => "用户带着问题进行提问，所以内容的准确性及丰富性会极大影响用户对准有好事问答的态度以及后续追问、连麦咨询等业务的支持，想要获得更高的收益一方面需要准确及丰富的回复用户的问题，一方面也可以在问题回复后适当的引导用户进行语音连麦咨询，提高收益。",
                ],
            ];

        }
        return show(config('code.success'), '请求成功', $data);
    }

    /**
     * 取消追问任务 已完成
     */
    public function cannelAddQuestion()
    {
        $id = input('id/d', 0);
        $tid = input('tid/d', 0);
        $reason = trim(input('reason/s', 0));
        $appType = input('app_type/d', 0);

        if (!$tid)
        {
            return show(config('code.error'), '请选择取消原因');
        }
        if (empty($reason))
        {
            return show(config('code.error'), '原因描述不能为空');
        }
        if (mb_strlen($reason) > 120)
        {
            return show(config('code.error'), '原因描述最多120字');
        }

        if ($appType == 1)
        {
            return $this->zhunleCannelAddQuestion($id, $tid, $reason);
        } else
        {
            return $this->zyhsCannelAddQuestion($id, $tid, $reason);
        }
    }

    /**
     * 准了 - 取消追问任务
     * @param int $id
     * @param int $tid
     * @param string $reason
     * @return Json
     */
    private function zhunleCannelAddQuestion(int $id, int $tid, string $reason)
    {
        $addQuestionModel = new Zlcr2UserAddQuestion();
        $questionModel = new Zlcr2UserQuestion();
        $addQuestionInfo = $addQuestionModel->getInfoById($id);
        if (!$addQuestionInfo)
        {
            return show(config('code.error'), '服务异常，追问不存在');
        }
        if ($addQuestionInfo['status'] !== 2)
        {
            return show(config('code.error'), '追问状态异常，取消失败');
        }
        $questionInfo = $questionModel->getInfoById($addQuestionInfo['qid'], ['astr_id', 'uid', 'reply_time']);
        if ($questionInfo['astr_id'] !== $this->astrInfo['id'])
        {
            return show(config('code.error'), '服务异常，追问不存在');
        }
        $tagInfo = (new ZlcrTag())->getInfoById($tid);
        if (!$tagInfo)
        {
            return show(config('code.error'), '服务异常，请稍后再试～');
        }
        if ($addQuestionInfo['order_num'])
        {   // 付费追问
            $OrderModel = new \app\common\cachemodel\Orders();
            $orders = $OrderModel->getInfoById($addQuestionInfo['order_num']);
            $res = $OrderModel->refund($questionInfo['uid'], $orders, $orders['total_amount']);
            if ($res['status'])
            {
                $addQuestionModel->UpdateData($addQuestionInfo['qid'], $id, [
                    'status' => 5,
                    'cannel_tag_name' => $tagInfo['tag_name'],
                    'cannel_cause' => $reason,
                ]);
                // 问题更新至 已回答 等待追问
                $questionModel->UpdateData($addQuestionInfo['qid'], ['status' => 5,]);
                if ($questionInfo['reply_time'] + 172800 < $this->request->time()) // 如果到完成的时候 直接完成 并结算
                {   // 不在追问时间范围内    172800=60*60*24*2 48小时
                    $taskId = (new Zlcr2AstrTasks())->where(['astr_id' => $questionInfo['astr_id'], 'qid' => $addQuestionInfo['qid']])->value('id');
                    if ($taskId)
                    {
                        Util::queuePush('question_answer_question_success_check', ['task_id' => (int)$taskId], 5);
                    }
                }
                // 发送消息
                // 消息中心添加信息
                $messageData = [
                    'status' => 0,
                    'is_read' => 0,
                    'range' => $questionInfo['uid'],
                    'type' => 2,
                    'reid' => 0,
                    'cid' => 4,//
                    'title' => '问答追问取消通知',
                    'content' => '你的追问订单：' . $addQuestionInfo['order_num'] . '，因问题违规被取消，资金将原路返还。',// 消息中心跳转地址
                    'link' => "question_detail?qid={$addQuestionInfo['qid']}&need_auth=0",
                    'target' => 'local',
                    'create_time' => $this->request->time(),
                ];
                (new MessageCenter())->pushMessage($questionInfo['uid'], $messageData);
                $pushData = ['action' => 'extend', 'target' => 'local', 'link' => "question_detail?qid={$addQuestionInfo['qid']}&need_auth=0"];
                // PUSH推送报告首页
                (new Push())->pushUserMsg($questionInfo['uid'], '你的追问订单：' . $addQuestionInfo['order_num'] . '，因问题违规被取消，资金将原路返还。', $pushData);
                // 发送短信通知
                $userInfo = (new User())->getUserinfo(['id' => $questionInfo['uid']]);
                if ($userInfo && $userInfo['tel'])
                {
                    Util::sendHySms([$userInfo['tel']], '', 52346, ['order_num' => $addQuestionInfo['order_num']]);
                }
                return show(config('code.success'), '取消成功');
            } else
            {
                Log::write('问答追问【' . $id . '】退款失败', 'error', true);
                return show(config('code.error'), '服务异常，请稍后再试～');
            }
        } else
        {   // 免费追问
            $addQuestionModel->UpdateData($addQuestionInfo['qid'], $id, [
                'status' => 5,
                'cannel_tag_name' => $tagInfo['tag_name'],
                'cannel_cause' => $reason,
            ]);
            // 问题更新至 已回答 等待追问
            $questionModel->UpdateData($addQuestionInfo['qid'], ['status' => 5,]);
            if ($questionInfo['reply_time'] + 172800 < $this->request->time()) // 如果到完成的时候 直接完成 并结算
            {   // 不在追问时间范围内    172800=60*60*24*2 48小时
                $taskId = (new Zlcr2AstrTasks())->where(['astr_id' => $questionInfo['astr_id'], 'qid' => $addQuestionInfo['qid']])->value('id');
                if ($taskId)
                {
                    Util::queuePush('question_answer_question_success_check', ['task_id' => (int)$taskId], 5);
                }
            }
            // 发送消息
            $messageData = [
                'status' => 0,
                'is_read' => 0,
                'range' => $questionInfo['uid'],
                'type' => 2,
                'reid' => 0,
                'cid' => 4,//
                'title' => '问答追问取消通知',
                'content' => '你开启的悬赏问答追问，因问题违规被取消，请重新追问',// 消息中心跳转地址
                'link' => "question_detail?qid={$addQuestionInfo['qid']}&need_auth=0",
                'target' => 'local',
                'create_time' => $this->request->time(),
            ];
            (new MessageCenter())->pushMessage($questionInfo['uid'], $messageData);
            $pushData = ['action' => 'extend', 'target' => 'local', 'link' => "question_detail?qid={$addQuestionInfo['qid']}&need_auth=0"];
            // PUSH推送报告首页
            (new Push())->pushUserMsg($questionInfo['uid'], '你开启的悬赏问答追问，因问题违规被取消，请重新追问', $pushData);
            // 发送短信通知
            $userInfo = (new User())->getUserinfo(['id' => $questionInfo['uid']]);
            if ($userInfo && $userInfo['tel'])
            {
                Util::sendHySms([$userInfo['tel']], '', 52347, []);
            }
            return show(config('code.success'), '取消成功');
        }
    }

    /**
     * 准有好事 - 取消追问任务
     * @param int $id
     * @param int $tid
     * @param string $reason
     * @return Json
     */
    private function zyhsCannelAddQuestion(int $id, int $tid, string $reason)
    {
        $zyhsUserAddQuestionModel = new ZyhsUserAddQuestion();
        $zyhsAstrTasksModel = new ZyhsAstrTasks();
        $addQuestionInfo = $zyhsUserAddQuestionModel->getInfoById($id);
        if (!$addQuestionInfo)
        {
            return show(config('code.error'), '服务异常，追问不存在');
        }
        if ($addQuestionInfo['status'] !== 2)
        {
            return show(config('code.error'), '追问状态异常，取消失败');
        }
        $taskInfo = $zyhsAstrTasksModel->getInfoById($addQuestionInfo['task_id'], ['qid', 'uid', 'astr_id', 'reply_time']);
        if ($taskInfo['astr_id'] !== $this->astrInfo['id'])
        {
            return show(config('code.error'), '服务异常，追问不存在');
        }
        $tagInfo = (new ZlcrTag())->getInfoById($tid);
        if (!$tagInfo)
        {
            return show(config('code.error'), '服务异常，请稍后再试～');
        }
        if ($addQuestionInfo['order_num'])
        {   // 付费追问
            $res = $zyhsUserAddQuestionModel->refund($id, '咨询师申请取消追问');
            // 退款
            if ($res['status'])
            {
                $zyhsUserAddQuestionModel->UpdateData($id, [
                    'status' => 5,
                    'cannel_tag_name' => $tagInfo['tag_name'],
                    'cannel_cause' => $reason,
                ]);
                $zyhsAstrTasksModel->UpdateData($addQuestionInfo['task_id'], $this->astrInfo['id'], ['status' => 3, 'update_time' => $this->request->time()]);
                if ($taskInfo['reply_time'] + 172800 < $this->request->time()) // 如果到完成的时候 直接完成 并结算
                {
                    Util::queuePush('zyhs_question_answer_question_success_check', ['task_id' => $addQuestionInfo['task_id']], 5);
                }
                // 发送消息
                // 消息中心添加信息
                $messageData = [
                    'status' => 0,
                    'is_read' => 0,
                    'range' => $taskInfo['uid'],
                    'type' => 2,
                    'reid' => 0,
                    'cid' => 4,//
                    'title' => '问答追问取消通知',
                    'content' => '你的追问订单：' . $addQuestionInfo['order_num'] . '，因问题违规被取消，资金将原路返还。',// 消息中心跳转地址
                    'link' => "question_detail?qid={$taskInfo['qid']}&need_auth=0",
                    'target' => 'local',
                    'create_time' => $this->request->time(),
                ];
                (new ZyhsMessageCenter())->pushMessage($taskInfo['uid'], $messageData);
                $pushData = [
                    'action' => 'extend',
                    'target' => 'local',
                    'link' => "question_detail?qid={$taskInfo['qid']}&need_auth=0",
                    'pop_msg' => json_encode([
                        'avatar' => $this->astrInfo['avatar'],
                        'name' => $this->astrInfo['nickname'],
                        'level' => $this->consultAccountInfo['level'] ?? 1,
                        'msg' => '悬赏问题追问已取消',
                        'target' => 'local',
                        'link' => "question_detail?qid={$taskInfo['qid']}&need_auth=0",
                        'astr_id' => $this->astrInfo['id'],
                    ], JSON_UNESCAPED_UNICODE),
                ];
                // PUSH推送报告首页
                (new ZyhsPush())->pushUserMsg($taskInfo['uid'], '你的追问订单：' . $addQuestionInfo['order_num'] . '，因问题违规被取消，资金将原路返还。', $pushData);
                // 发送短信通知
                $userInfo = (new ZyhsUser())->getInfoById($taskInfo['uid'], ['tel']);
                if ($userInfo && $userInfo['tel'])
                {   // 短信通知
                    Alidayu::getInstance()->zyhsMsgSmsSend(86, $userInfo['tel'], 'SMS_464330292', ['order_num' => $addQuestionInfo['order_num']]);
                }
            } else
            {
                Log::write('准有好事 - 问答追问【' . $id . '】退款失败', 'error', true);
                return show(config('code.error'), '服务异常，请稍后再试～');
            }
            return show(config('code.success'), '取消成功');
        } else
        {   // 免费追问
            $zyhsUserAddQuestionModel->UpdateData($id, [
                'status' => 5,
                'cannel_tag_name' => $tagInfo['tag_name'],
                'cannel_cause' => $reason,
            ]);
            $zyhsAstrTasksModel->UpdateData($addQuestionInfo['task_id'], $this->astrInfo['id'], ['status' => 3, 'update_time' => $this->request->time()]);
            if ($taskInfo['reply_time'] + 172800 < $this->request->time()) // 如果到完成的时候 直接完成 并结算
            {
                Util::queuePush('zyhs_question_answer_question_success_check', ['task_id' => $addQuestionInfo['task_id']], 5);
            }
            // 发送消息
            $messageData = [
                'status' => 0,
                'is_read' => 0,
                'range' => $taskInfo['uid'],
                'type' => 2,
                'reid' => 0,
                'cid' => 4,//
                'title' => '问答追问取消通知',
                'content' => '你开启的悬赏问答追问，因问题违规被取消，请重新追问',// 消息中心跳转地址
                'link' => "question_detail?qid={$taskInfo['qid']}&need_auth=0",
                'target' => 'local',
                'create_time' => $this->request->time(),
            ];
            (new ZyhsMessageCenter())->pushMessage($taskInfo['uid'], $messageData);
            $pushData = [
                'action' => 'extend',
                'target' => 'local',
                'link' => "question_detail?qid={$taskInfo['qid']}&need_auth=0",
                'pop_msg' => json_encode([
                    'avatar' => $this->astrInfo['avatar'],
                    'name' => $this->astrInfo['nickname'],
                    'level' => $this->consultAccountInfo['level'] ?? 1,
                    'msg' => '悬赏问题追问已取消',
                    'target' => 'local',
                    'link' => "question_detail?qid={$taskInfo['qid']}&need_auth=0",
                    'astr_id' => $this->astrInfo['id'],
                ], JSON_UNESCAPED_UNICODE),
            ];
            // PUSH推送报告首页
            (new ZyhsPush())->pushUserMsg($taskInfo['uid'], '你开启的悬赏问答追问，因问题违规被取消，请重新追问', $pushData);
            // 发送短信通知
//             $userInfo = (new ZyhsUser())->getInfoById($taskInfo['uid'], ['tel']);
//             if ($userInfo && $userInfo['tel'])
//             {   //  短信通知
// //                Util::sendHySms([$userInfo['tel']], '', 52347, []);
//             }
            return show(config('code.success'), '取消成功');
        }
    }

    /**
     * 问答历史任务
     */
    public function getAstrTaskRecordList()
    {
        $questionType = input('question_type/d', 0);
        $appType = input('app_type/d', 1);
        if (!in_array($appType, [1, 2], true))
        {
            return show(config('code.error'), '请求异常，请稍后再试～');
        }
        if ($appType === 1)
        {
            return $this->zhunleGetAstrTaskRecordList($questionType);
        } else
        {
            return $this->zyhsGetAstrTaskRecordList($questionType);
        }
    }

    /**
     * 准了 - 问答历史任务列表
     * @param int $questionType
     * @return Json
     * @throws \Exception
     */
    private function zhunleGetAstrTaskRecordList(int $questionType)
    {
        $map = ['t.astr_id' => $this->astrInfo['id'], 't.status' => ['in', [2, 3, 4, 5, 6, 7]]];
        if ($questionType)
        {
            $map['t.question_type'] = $questionType;
        }
        $astrModel = new ZlcrAstr();
        $zlcr2UserQuestionComment = new Zlcr2UserQuestionComment();
        $addQuestionModel = new Zlcr2UserAddQuestion();

        $data = Db::table('wechat_backup_07_18_14_43_00.zlcr2_astr_tasks')->alias('t')
            ->join('wechat_backup_07_18_14_43_00.zlcr2_user_question q', 't.qid=q.id')
            ->field('t.id task_id,q.id qid,q.question_type,q.uid,q.is_synastry is_merge,t.create_time astr_receiving_time,q.is_anonymity,q.question,q.status,q.is_comment,q.success_time,t.earning,t.qa_level,t.status tstatus,t.deduct_earning_time,t.update_time,t.lock_earning')
            ->where($map)
            ->order('t.id desc')
            ->paginate()
            ->toArray();

        $resData = [];
        $statusDes = [  // 状态 1=>进行中 2=>已完成 3=>已弃答 4=>用户申述已取消 5=>答案回复超时 6追问回复超时未完成 7=>抽查被扣除收益
            2 => '已完成',
            3 => '已弃答',
            4 => '扣除收益',
            5 => '已取消：回复超时',
            6 => '扣除收益：追问回复超时',
            7 => '扣除收益',
        ];
        $userInfoList = [];
        foreach ($data['data'] as $datum)
        {
            $datum['tstatus'] = $datum['tstatus'] === 7 ? 4 : $datum['tstatus'];
            $tagName = '';
            if ($datum['is_comment'])
            {
                $commentInfo = $zlcr2UserQuestionComment->getInfoById($datum['qid'], ['tag_name', 'level', 'comment']);
                $tagName = $commentInfo['tag_name'];
            }
            $addQuestionNum = $addQuestionModel->getQuestionAddQuestionNum($datum['qid']);
            $proportion = ($astrModel->getAstrQuestionAnswerProportion((int)$datum['astr_receiving_time'], (int)$datum['question_type'], (int)$datum['qa_level']) * 100) . '%';

            $nickname = '匿名用户';
            $avatar = '/test/question_answer/anonymity1.png';
            if ($datum['is_anonymity'] !== 1)
            {
                if (isset($userInfoList[$datum['uid']]))
                {
                    $nickname = $userInfoList[$datum['uid']]['nickname'];
                    $avatar = $userInfoList[$datum['uid']]['avatar'];
                } else
                {
                    $userInfo = (new User())->getUserinfo(['id' => $datum['uid']]);
                    $nickname = $userInfo['nickname'];
                    $avatar = $userInfo['avatar'];
                    $userInfoList[$datum['uid']] = [
                        'nickname' => $nickname,
                        'avatar' => $avatar,
                    ];
                }
            }

            $desList = [
                [
                    'title' => '任务编号:',
                    'des' => $datum['qid'],
                    'type' => 0,
                ],
            ];
            $status = (int)$datum['tstatus'];
            if ($status === 2 && (int)$datum['lock_earning'] === 1)
            {
                $status = 7;
            }
            if ($status === 5)
            {
                $desList[] = [
                    'title' => '取消时间:',
                    'des' => date('Y-m-d H:i:s', $datum['update_time']),
                    'type' => 1,
                ];
            } elseif ($status === 3)
            {
                $desList[] = [
                    'title' => '弃答时间:',
                    'des' => date('Y-m-d H:i:s', $datum['update_time']),
                    'type' => 1,
                ];
            } else
            {
                $desList[] = [
                    'title' => '税前收益:',
                    'des' => $datum['earning'],
                    'type' => 1,
                ];
                $desList[] = [
                    'title' => '分成比例:',
                    'des' => $proportion,
                    'type' => 1,
                ];
                $desList[] = [
                    'title' => '追问次数:',
                    'des' => $addQuestionNum . '次',
                    'type' => 1,
                ];
                if ($status === 2)
                {   // 已完成   评价信息
                    $desList[] = [
                        'title' => '评价状态:',
                        'des' => $datum['is_comment'] ? (string)$commentInfo['level'] ?? '3' : '未评价',
                        'type' => $datum['is_comment'] ? 2 : 1,
                    ];
                }
                $desList[] = [
                    'title' => '完成时间:',
                    'des' => $status === 6 ? date('Y-m-d H:i:s', $datum['deduct_earning_time']) : date('Y-m-d H:i:s', $datum['success_time']),
                    'type' => 1,
                ];
                if (in_array($status, [6, 7], true))
                {
                    $desList[] = [
                        'title' => '扣除时间:',
                        'des' => date('Y-m-d H:i:s', $datum['deduct_earning_time']),
                        'type' => 1,
                    ];
                }
            }

            $successTime = in_array($status, [3, 5, 7], true) ? date('Y-m-d H:i:s', $datum['update_time']) : date('Y-m-d H:i:s', $datum['success_time']);

            $resData[] = [
                'task_id' => (int)$datum['task_id'],
                'qid' => $datum['qid'],
                'question_type' => (int)$datum['question_type'],
                'question' => $datum['question'],
                'nickname' => $nickname,
                'avatar' => $avatar,
                'is_merge' => (int)$datum['is_merge'],
                'astr_receiving_time' => date('Y-m-d H:i:s', $datum['astr_receiving_time']),
                'success_time' => $status === 6 ? date('Y-m-d H:i:s', $datum['deduct_earning_time']) : $successTime,
                'add_question_num' => $addQuestionNum,
                'is_comment' => (int)$datum['is_comment'],
                'comment_level' => $commentInfo['level'] ?? 0,
                'comment_tag_name' => $tagName,
                'comment' => $commentInfo['comment'] ?? '',
                'earnings' => $datum['earning'],
                'proportion' => $proportion,
                'status' => (int)$status,
                'status_des' => $statusDes[$datum['tstatus']],
                'des_list' => $desList,
            ];
        }
        $data['data'] = $resData;

        return show(config('code.success'), '请求成功', $data);
    }

    /**
     * 准有好事 - 问答历史任务列表
     * @param int $questionType
     * @return Json
     */
    private function zyhsGetAstrTaskRecordList(int $questionType)
    {
        $map = ['t.astr_id' => $this->astrInfo['id'], 't.status' => ['in', [2, 4, 6, 7, 8, 9, 10]]];
        if ($questionType)
        {
            $map['t.question_type'] = $questionType;
        }

        $data = Db::table('good_wechat.zyhs_astr_tasks')->alias('t')
            ->join('good_wechat.zyhs_user_question q', 't.qid=q.id')
            ->field('t.id task_id,q.id qid,q.question_type,q.uid,q.is_synastry is_merge,t.create_time astr_receiving_time,q.question,t.is_comment,t.success_time,t.earning,t.level,t.status tstatus,t.deduct_earning_time,t.update_time,t.lock_earning')
            ->where($map)
            ->order('t.id desc')
            ->paginate()
            ->toArray();
        $zyhsUserQuestionCommentModel = new ZyhsUserQuestionComment();
        $zlcr3ConsultAccountModel = new Zlcr3ConsultAccount();
        $zyhsUserAddQuestionModel = new ZyhsUserAddQuestion();
        $resData = [];
        $statusDes = [
            2 => '已弃答',
            4 => '扣除收益：追问回复超时',
            6 => '已完成',
            7 => '已取消：回复超时',
            8 => '扣除收益',
            9 => '扣除收益：追问回复超时',
            10 => '扣除收益',
        ];
        $proportionData = $zlcr3ConsultAccountModel->getQuestionAnswerPercent();
        $proportion = ($proportionData['question'] * 100) . '%';
        $userInfoList = [];
        foreach ($data['data'] as $key => $datum)
        {
            $tagName = '';
            if ($datum['is_comment'])
            {
                $commentInfo = $zyhsUserQuestionCommentModel->getCommentData($datum['task_id']);
                $tagName = $commentInfo ? implode(' ', $commentInfo['tag_names']) : '';
            }
            $addQuestionNum = $zyhsUserAddQuestionModel->getQuestionAddQuestionNum($datum['task_id']);
            if (isset($userInfoList[$datum['uid']]))
            {
                $nickname = $userInfoList[$datum['uid']]['nickname'];
                $avatar = $userInfoList[$datum['uid']]['avatar'];
            } else
            {
                $userInfo = (new ZyhsUser())->getInfoById($datum['uid']);
                $nickname = $userInfo['nickname'];
                $avatar = $userInfo['avatar'];
                $userInfoList[$datum['uid']] = [
                    'nickname' => $nickname,
                    'avatar' => $avatar,
                ];
            }

            $desList = [
                [
                    'title' => '任务编号:',
                    'des' => (string)$datum['task_id'],
                    'type' => 0,
                ],
            ];
            $status = (int)$datum['tstatus'];

            if (in_array($status, [6, 8, 10], true))
            {
                $successTime = date('Y-m-d H:i:s', $datum['success_time']);
            } elseif (in_array($status, [2, 7], true))
            {   // if (in_array($status, [2, 7], true))
                $successTime = date('Y-m-d H:i:s', $datum['update_time']);
            } else
            {   // 4,9
                $successTime = date('Y-m-d H:i:s', $datum['deduct_earning_time']);
            }
            // 状态
            //  1=>待解答【已接单】
            //  2=>已弃答
            //  3=>已解答【可追问48小时后自动完成】
            //  4=>已解答【追问回复超时，不可追问48小时后自动完成】
            //  5=>追问待解答
            //  6=>已完成
            //  7=>答案回复超时
            //  8=>已完成且收益扣除【用户申述已取消】
            //  9=>已完成且收益扣除【追问回复超时未完成】
            //  10=>已完成且收益扣除 后台本单冻结[必须已完成后才能冻结]
            if ($status === 7)
            {
                $desList[] = [
                    'title' => '取消时间:',
                    'des' => date('Y-m-d H:i:s', $datum['update_time']),
                    'type' => 1,
                ];
            } elseif ($status === 2)
            {
                $desList[] = [
                    'title' => '弃答时间:',
                    'des' => date('Y-m-d H:i:s', $datum['update_time']),
                    'type' => 1,
                ];
            } else
            {
                $desList[] = [
                    'title' => '税前收益:',
                    'des' => $datum['earning'],
                    'type' => 1,
                ];
                $desList[] = [
                    'title' => '分成比例:',
                    'des' => $proportion,
                    'type' => 1,
                ];
                $desList[] = [
                    'title' => '追问次数:',
                    'des' => $addQuestionNum . '次',
                    'type' => 1,
                ];
                if ($status === 6)
                {   // 已完成   评价信息
                    $desList[] = [
                        'title' => '评价状态:',
                        'des' => $datum['is_comment'] ? (string)$commentInfo['level'] ?? '3' : '未评价',
                        'type' => $datum['is_comment'] ? 2 : 1,
                    ];
                }
                $desList[] = [
                    'title' => '完成时间:',
                    'des' => $successTime,
                    'type' => 1,
                ];
                if (in_array($status, [4, 8, 9, 10], true))
                {
                    $desList[] = [
                        'title' => '扣除时间:',
                        'des' => date('Y-m-d H:i:s', $datum['deduct_earning_time']),
                        'type' => 1,
                    ];
                }
            }

            $resData[] = [
                'task_id' => (int)$datum['task_id'],
                'qid' => $datum['qid'],
                'question_type' => (int)$datum['question_type'],
                'question' => $datum['question'],
                'nickname' => $nickname,
                'avatar' => $avatar,
                'is_merge' => (int)$datum['is_merge'],
                'astr_receiving_time' => date('Y-m-d H:i:s', $datum['astr_receiving_time']),
                'success_time' => $successTime,
                'add_question_num' => $addQuestionNum,
                'is_comment' => (int)$datum['is_comment'],
                'comment_level' => $commentInfo['level'] ?? 0,
                'comment_tag_name' => $tagName,
                'comment' => $commentInfo['comment'] ?? '',
                'earnings' => $datum['earning'],
                'proportion' => $proportion,
                'status' => (int)$status,
                'status_des' => $statusDes[$datum['tstatus']],
                'des_list' => $desList,
            ];
        }
        $data['data'] = $resData;

        return show(config('code.success'), '请求成功', $data);
    }
}
